vendor/bluue/cx3-bundle/src/EventSubscriber/ConfigureSubMenuSubscriber.php line 50

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bluue\Cx3Bundle\EventSubscriber;
  4. use App\Event\MenuConfigurationPageEvent;
  5. use Symfony\Component\Security\Core\Security;
  6. use Symfony\Contracts\Translation\TranslatorInterface;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class ConfigureSubMenuSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var TranslatorInterface
  12.      */
  13.     private TranslatorInterface $tr;
  14.     /**
  15.      * @var Security
  16.      */
  17.     private Security $security;
  18.     /**
  19.      * @param TranslatorInterface $tr
  20.      * @param Security $security
  21.      */
  22.     public function __construct(
  23.         TranslatorInterface $tr,
  24.         Security $security
  25.     ) {
  26.         $this->tr $tr;
  27.         $this->security $security;
  28.     }
  29.     /**
  30.      * @return string[]
  31.      */
  32.     public static function getSubscribedEvents(): array
  33.     {
  34.         return [
  35.             MenuConfigurationPageEvent::NAME => 'onLoad'
  36.         ];
  37.     }
  38.     /**
  39.      * @param MenuConfigurationPageEvent $event
  40.      * @return void
  41.      */
  42.     public function onLoad(MenuConfigurationPageEvent $event): void
  43.     {
  44.         if ($this->security->isGranted('ROLE_ADMIN')) {
  45.             $pages $event->getPages();
  46.             $pages[] = [
  47.                 'id' => 'cx3_bundle__configuration_settings',
  48.                 'name' => $this->tr->trans('3CX Module', [], 'Cx3Bundle'),
  49.                 'subpages' => [
  50.                     ['id' => 'cx3_bundle__configuration_settings']
  51.                 ]
  52.             ];
  53.             $event->setPages($pages);
  54.         }
  55.     }
  56. }