-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(attributes): AsFilter attribute
- Loading branch information
1 parent
d654fe3
commit bfb5387
Showing
6 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Component\Grid\Metadata; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
final class AsFilter | ||
{ | ||
public function __construct( | ||
public ?string $type = null, | ||
public ?string $formType = null, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests/Application/src/Filter/AttributeNationalityFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filter; | ||
|
||
use App\Grid\Type\NationalityFilterType; | ||
use Sylius\Component\Grid\Data\DataSourceInterface; | ||
use Sylius\Component\Grid\Filter\EntityFilter; | ||
use Sylius\Component\Grid\Filtering\FilterInterface; | ||
use Sylius\Component\Grid\Metadata\AsFilter; | ||
|
||
#[AsFilter( | ||
type: 'attribute_nationality', | ||
formType: NationalityFilterType::class, | ||
)] | ||
final class AttributeNationalityFilter implements FilterInterface | ||
{ | ||
public function __construct(private EntityFilter $decorated) | ||
{ | ||
} | ||
|
||
public function apply(DataSourceInterface $dataSource, string $name, $data, array $options): void | ||
{ | ||
$this->decorated->apply($dataSource, $name, $data, $options); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/Application/src/Grid/Builder/AttributeNationalityFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Grid\Builder; | ||
|
||
use App\Entity\Nationality; | ||
use App\Grid\Type\NationalityFilterType; | ||
use Sylius\Bundle\GridBundle\Builder\Filter\Filter; | ||
use Sylius\Bundle\GridBundle\Builder\Filter\FilterInterface; | ||
|
||
final class AttributeNationalityFilter | ||
{ | ||
public static function create(string $name, ?bool $multiple = null, ?array $fields = null): FilterInterface | ||
{ | ||
$filter = Filter::create($name, $name); | ||
|
||
$filter->setFormOptions(['class' => Nationality::class]); | ||
|
||
if (null !== $fields) { | ||
$filter->setOptions(['fields' => $fields]); | ||
} | ||
|
||
if (null !== $multiple) { | ||
$filter->addFormOption('multiple', $multiple); | ||
} | ||
|
||
return $filter; | ||
} | ||
} |