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

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bluue\ShipmentsBundle\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.     protected 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('sales_bundle__display_all_contexts');
  43.         $shared_products $this->configService->get('sales_bundle__shared_sales');
  44.         if ($all_contexts && $shared_products) {
  45.             $routes = [
  46.                 'shipments_bundle__order_list',
  47.                 'shipments_bundle__burst_list',
  48.                 'shipments_bundle__burst_sheet',
  49.                 'shipments_bundle__burst_sheet_advanced_picking',
  50.                 'shipments_bundle__burst_sheet_advanced_order_preparation',
  51.             ];
  52.             foreach ($routes as $route) {
  53.                 $currentRoute $this->requestStack->getMainRequest()->attributes->get('_route');
  54.                 if ($currentRoute === $route) {
  55.                     $event->setAllContexts(true);
  56.                     break;
  57.                 }
  58.             }
  59.         }
  60.     }
  61. }