-
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 81ae79d
Showing
7 changed files
with
130 additions
and
13 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
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,28 @@ | ||
<?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 | ||
{ | ||
/** | ||
* @param string $formType The form type class name to use for filter rendering | ||
* @param string|null $type The filter type (defaults to FQCN of the class) | ||
*/ | ||
public function __construct( | ||
public string $formType, | ||
public ?string $type = 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
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
<?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( | ||
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\Filter\AttributeNationalityFilter as GridNationalityFilter; | ||
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, GridNationalityFilter::class); | ||
|
||
$filter->setFormOptions(['class' => Nationality::class]); | ||
|
||
if (null !== $fields) { | ||
$filter->setOptions(['fields' => $fields]); | ||
} | ||
|
||
if (null !== $multiple) { | ||
$filter->addFormOption('multiple', $multiple); | ||
} | ||
|
||
return $filter; | ||
} | ||
} |