diff --git a/docs/custom_filter.md b/docs/custom_filter.md index 850c602d..c1d85a6a 100644 --- a/docs/custom_filter.md +++ b/docs/custom_filter.md @@ -13,7 +13,7 @@ namespace App\Grid\Filter; use App\Form\Type\Filter\SuppliersStatisticsFilterType; use Sylius\Bundle\GridBundle\Doctrine\DataSourceInterface; use Sylius\Component\Grid\Filtering\FilterInterface; -use Sylius\Component\Grid\Metadata\AsFilter; +use Sylius\Component\Grid\Attribute\AsFilter; #[AsFilter(formType: SuppliersStatisticsFilterType::class)] class SuppliersStatisticsFilter implements FilterInterface diff --git a/src/Bundle/DependencyInjection/SyliusGridExtension.php b/src/Bundle/DependencyInjection/SyliusGridExtension.php index da797a55..49e0a70f 100644 --- a/src/Bundle/DependencyInjection/SyliusGridExtension.php +++ b/src/Bundle/DependencyInjection/SyliusGridExtension.php @@ -16,9 +16,9 @@ use Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle; use Sylius\Bundle\GridBundle\Grid\GridInterface; use Sylius\Bundle\GridBundle\SyliusGridBundle; +use Sylius\Component\Grid\Attribute\AsFilter; use Sylius\Component\Grid\Data\DataProviderInterface; use Sylius\Component\Grid\Filtering\FilterInterface; -use Sylius\Component\Grid\Metadata\AsFilter; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -62,16 +62,20 @@ public function load(array $configs, ContainerBuilder $container): void ->addTag('sylius.grid') ; - $container->registerAttributeForAutoconfiguration(AsFilter::class, function (ChildDefinition $definition, AsFilter $attribute, \Reflector $reflector): void { - if (!$reflector instanceof \ReflectionClass) { - throw new \LogicException(sprintf('The attribute "%s" can only be used on classes.', AsFilter::class)); - } - $tagAttributes = [ - 'type' => $attribute->type ?? $reflector->getName(), - 'form_type' => $attribute->formType, - ]; - $definition->addTag('sylius.grid_filter', $tagAttributes); - }); + $container->registerAttributeForAutoconfiguration( + AsFilter::class, + static function (ChildDefinition $definition, AsFilter $attribute, \Reflector $reflector): void { + // Helps to avoid issues with psalm + if (!$reflector instanceof \ReflectionClass) { + return; + } + + $definition->addTag(AsFilter::SERVICE_TAG, [ + 'type' => $attribute->getType() ?? $reflector->getName(), + 'form_type' => $attribute->getFormType(), + ]); + }, + ); $container->registerForAutoconfiguration(FilterInterface::class) ->addTag('sylius.grid_filter') diff --git a/src/Component/Attribute/AsFilter.php b/src/Component/Attribute/AsFilter.php new file mode 100644 index 00000000..8207824d --- /dev/null +++ b/src/Component/Attribute/AsFilter.php @@ -0,0 +1,39 @@ +formType; + } + + public function getType(): ?string + { + return $this->type; + } +} diff --git a/src/Component/Metadata/AsFilter.php b/src/Component/Metadata/AsFilter.php deleted file mode 100644 index ad41d42b..00000000 --- a/src/Component/Metadata/AsFilter.php +++ /dev/null @@ -1,28 +0,0 @@ -