vendor/coreshop/pimcore-bundle/EventListener/Grid/ObjectListFilterListener.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * CoreShop
  5.  *
  6.  * This source file is available under two different licenses:
  7.  *  - GNU General Public License version 3 (GPLv3)
  8.  *  - CoreShop Commercial License (CCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  * @copyright  Copyright (c) CoreShop GmbH (https://www.coreshop.org)
  13.  * @license    https://www.coreshop.org/license     GPLv3 and CCL
  14.  *
  15.  */
  16. namespace CoreShop\Bundle\PimcoreBundle\EventListener\Grid;
  17. use CoreShop\Component\Pimcore\DataObject\Grid\GridFilterInterface;
  18. use CoreShop\Component\Registry\ServiceRegistryInterface;
  19. use Symfony\Component\EventDispatcher\GenericEvent;
  20. final class ObjectListFilterListener
  21. {
  22.     public function __construct(
  23.         private ServiceRegistryInterface $filterServiceRegistry,
  24.     ) {
  25.     }
  26.     public function checkObjectList(GenericEvent $event): void
  27.     {
  28.         $list $event->getArgument('list');
  29.         $context $event->getArgument('context');
  30.         if (!isset($context['coreshop_filter'])) {
  31.             return;
  32.         }
  33.         $filter $context['coreshop_filter'];
  34.         if (!$this->filterServiceRegistry->has($filter)) {
  35.             return;
  36.         }
  37.         /** @var GridFilterInterface $filterService */
  38.         $filterService $this->filterServiceRegistry->get($filter);
  39.         $data $filterService->filter($list$context);
  40.         $event->setArgument('list'$data);
  41.     }
  42. }