vendor/bluue/adelya-bundle/src/EventSubscriber/ConfigurationBundleSubscriber.php line 58

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Thomas HERISSON (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\AdelyaBundle\EventSubscriber;
  9. use App\Event\MenuConfigurationPageEvent;
  10. use Bluue\CashRegisterBundle\Event\MenuConfigurationPageCashRegisterEvent;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class ConfigurationBundleSubscriber implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @var TranslatorInterface
  18.      */
  19.     private TranslatorInterface $tr;
  20.     /**
  21.      * @var RequestStack
  22.      */
  23.     protected RequestStack $requestStack;
  24.     /**
  25.      * @param RequestStack $requestStack
  26.      * @param TranslatorInterface $tr
  27.      */
  28.     public function __construct(
  29.         RequestStack $requestStack,
  30.         TranslatorInterface $tr
  31.     ) {
  32.         $this->requestStack $requestStack;
  33.         $this->tr $tr;
  34.     }
  35.     /**
  36.      * @return string[]
  37.      */
  38.     public static function getSubscribedEvents(): array
  39.     {
  40.         return [
  41.             MenuConfigurationPageEvent::NAME => 'configurationMenu',
  42.             MenuConfigurationPageCashRegisterEvent::NAME => 'cashRegisterMenu',
  43.         ];
  44.     }
  45.     /**
  46.      * @param MenuConfigurationPageEvent $event
  47.      * @return void
  48.      */
  49.     public function configurationMenu(MenuConfigurationPageEvent $event): void
  50.     {
  51.         $pages $event->getPages();
  52.         $keyCashRegisterMenu array_search('adelya_bundle__configuration_settings'array_column($pages'id'));
  53.         if (is_numeric($keyCashRegisterMenu)) {
  54.             $pages[$keyCashRegisterMenu]['subpages'][] = ['id' => 'adelya_bundle__configuration_settings'];
  55.             $event->setPages($pages);
  56.         }
  57.     }
  58.     /**
  59.      * @param MenuConfigurationPageCashRegisterEvent $event
  60.      * @return void
  61.      */
  62.     public function cashRegisterMenu(MenuConfigurationPageCashRegisterEvent $event): void
  63.     {
  64.         $pages $event->getPages();
  65.         $pages[] = [
  66.             'id' => 'adelya_bundle__configuration_settings',
  67.             'name' => $this->tr->trans('Adelya', [], 'AdelyaBundle')
  68.         ];
  69.         $event->setPages($pages);
  70.     }
  71. }