vendor/bluue/cx3-bundle/src/EventSubscriber/ConfigureMenuEventSubscriber.php line 59

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bluue\Cx3Bundle\EventSubscriber;
  4. use App\Event\ConfigureMenuEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Component\Security\Core\Security;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. class ConfigureMenuEventSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var TranslatorInterface
  13.      */
  14.     private TranslatorInterface $tr;
  15.     /**
  16.      * @var RequestStack
  17.      */
  18.     protected RequestStack $requestStack;
  19.     /**
  20.      * @var Security
  21.      */
  22.     private Security $security;
  23.     /**
  24.      * @param RequestStack $requestStack
  25.      * @param TranslatorInterface $tr
  26.      * @param Security $security
  27.      */
  28.     public function __construct(
  29.         RequestStack $requestStack,
  30.         TranslatorInterface $tr,
  31.         Security $security
  32.     ) {
  33.         $this->requestStack $requestStack;
  34.         $this->tr $tr;
  35.         $this->security $security;
  36.     }
  37.     /**
  38.      * @return string[]
  39.      */
  40.     public static function getSubscribedEvents(): array
  41.     {
  42.         return [
  43.             ConfigureMenuEvent::NAME => 'onLoad'
  44.         ];
  45.     }
  46.     /**
  47.      * @param ConfigureMenuEvent $event
  48.      * @return void
  49.      */
  50.     public function onLoad(ConfigureMenuEvent $event): void
  51.     {
  52.         $menu $event->getMenu();
  53.         $menuSAVChilds = [
  54.             [
  55.                 'key' => 'calls',
  56.                 'label' => $this->tr->trans('Calls', [], 'Cx3Bundle'),
  57.                 'route' => 'cx3_bundle__call_list',
  58.             ]
  59.         ];
  60.         $currentPath $this->requestStack->getCurrentRequest()->getPathInfo();
  61.         $currentRoute $this->requestStack->getCurrentRequest()->attributes->get('_route');
  62.         $parentName $this->tr->trans('SAV', [], 'Cx3Bundle');
  63.         $menu->addChild('SAVMenu')
  64.             ->setLabel($parentName)
  65.             ->setExtra('icon''fas fa-users')
  66.         ;
  67.         foreach ($menuSAVChilds as $menuSAVChild) {
  68.             $current $menuSAVChild['route'] == $currentRoute
  69.                 || (
  70.                     !empty($menuSAVChild['matchPath'])
  71.                     && strpos($currentPath$menuSAVChild['matchPath']) !== false
  72.                 )
  73.             ;
  74.             $menu['SAVMenu']->addChild(
  75.                 $menuSAVChild['key'],
  76.                 [
  77.                     'route' => $menuSAVChild['route'],
  78.                     'label' => $menuSAVChild['label'],
  79.                     'current' => $current
  80.                 ]
  81.             );
  82.         }
  83.     }
  84. }