vendor/bluue/products-bundle/src/EventSubscriber/SharedContextSubscriber.php line 48

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bluue\ProductsBundle\EventSubscriber;
  4. use App\Event\SharedContextEvent;
  5. use App\Services\Configuration;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. class SharedContextSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var Configuration
  12.      */
  13.     private Configuration $configService;
  14.     /**
  15.      * @var RequestStack
  16.      */
  17.     private RequestStack $requestStack;
  18.     /**
  19.      * @param Configuration $configService
  20.      * @param RequestStack $requestStack
  21.      */
  22.     public function __construct(Configuration $configServiceRequestStack $requestStack)
  23.     {
  24.         $this->configService $configService;
  25.         $this->requestStack $requestStack;
  26.     }
  27.     /**
  28.      * @return string[]
  29.      */
  30.     public static function getSubscribedEvents(): array
  31.     {
  32.         return [
  33.             SharedContextEvent::NAME => 'onLoad'
  34.         ];
  35.     }
  36.     /**
  37.      * @param SharedContextEvent $event
  38.      * @return void
  39.      */
  40.     public function onLoad(SharedContextEvent $event): void
  41.     {
  42.         $all_contexts $this->configService->get('products_bundle__display_all_contexts');
  43.         $shared_products $this->configService->get('products_bundle__shared_products');
  44.         if ($all_contexts && $shared_products) {
  45.             $routes = [
  46.                 'products_bundle__product_list',
  47.                 'products_bundle__brand_list',
  48.                 'products_bundle__attribute_group_list',
  49.                 'products_bundle__attribute_list',
  50.                 'products_bundle__feature_list',
  51.                 'products_bundle__feature_value_list'
  52.             ];
  53.             foreach ($routes as $route) {
  54.                 $currentRoute $this->requestStack->getMainRequest()->attributes->get('_route');
  55.                 if ($currentRoute === $route) {
  56.                     $event->setAllContexts(true);
  57.                     break;
  58.                 }
  59.             }
  60.         }
  61.     }
  62. }