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

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bluue\StocksBundle\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('stocks_bundle__display_all_contexts');
  43.         $shared_products $this->configService->get('products_bundle__shared_products');
  44.         if ($all_contexts && $shared_products) {
  45.             $routes = [
  46.                 'stocks_bundle__stock_product_list',
  47.                 'stocks_bundle__stock_movement_list',
  48.                 'stocks_bundle__location_list',
  49.                 'stocks_bundle__sub_location_list',
  50.                 'stocks_bundle__stock_location_limit_date_list',
  51.                 'stocks_bundle__stock_preparation_list',
  52.                 'stocks_bundle__mass_stock_entry_list',
  53.                 'stocks_bundle__mass_stock_removal_list',
  54.                 'stocks_bundle__product_restock_list',
  55.                 'stocks_bundle__product_restock_holding_list',
  56.                 'stocks_bundle__product_quantity_to_hold_list',
  57.                 'forecasted_stock_bundle__list'
  58.             ];
  59.             foreach ($routes as $route) {
  60.                 $currentRoute $this->requestStack->getMainRequest()->attributes->get('_route');
  61.                 if ($currentRoute === $route) {
  62.                     $event->setAllContexts(true);
  63.                     break;
  64.                 }
  65.             }
  66.         }
  67.     }
  68. }