vendor/bluue/stocks-bundle/src/EventSubscriber/ConfigurationMenuSubscriber.php line 45

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Léo BANNHOLTZER (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace Bluue\StocksBundle\EventSubscriber;
  9. use App\Event\MenuConfigurationPageEvent;
  10. use Symfony\Component\Security\Core\Security;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class ConfigurationMenuSubscriber implements EventSubscriberInterface
  14. {
  15.     private TranslatorInterface $tr;
  16.     private Security $security;
  17.     public function __construct(
  18.         TranslatorInterface $tr,
  19.         Security $security
  20.     ) {
  21.         $this->tr $tr;
  22.         $this->security $security;
  23.     }
  24.     /**
  25.      * @return array
  26.      */
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             MenuConfigurationPageEvent::NAME => 'onLoad'
  31.         ];
  32.     }
  33.     /**
  34.      * @param MenuConfigurationPageEvent $event
  35.      * @return void
  36.      */
  37.     public function onLoad(MenuConfigurationPageEvent $event): void
  38.     {
  39.         if ($this->security->isGranted('ROLE__STOCKS__ADMIN')) {
  40.             $pages $event->getPages();
  41.             $pages[] = [
  42.                 'id' => 'stocks_bundle__configuration_settings',
  43.                 'name' => $this->tr->trans('Stocks Module', [], 'StocksBundle'),
  44.                 'subpages' => [
  45.                     ['id' => 'stocks_bundle__configuration_settings'],
  46.                     ['id' => 'stocks_bundle__warehouse_list'],
  47.                     ['id' => 'stocks_bundle__stock_movement_reason_list'],
  48.                     ['id' => 'stocks_bundle__date_type_list'],
  49.                     ['id' => 'stocks_bundle__warehouses_context_list']
  50.                 ]
  51.             ];
  52.             $event->setPages($pages);
  53.         }
  54.     }
  55. }