vendor/bluue/colissimo-bundle/src/EventSubscriber/ConfigureShipmentsMenuSubscriber.php line 43

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\ColissimoBundle\EventSubscriber;
  9. use App\Event\MenuConfigurationPageEvent;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Bluue\ShipmentsBundle\Event\MenuConfigurationPageShipmentsEvent;
  13. class ConfigureShipmentsMenuSubscriber implements EventSubscriberInterface
  14. {
  15.     private TranslatorInterface $tr;
  16.     public function __construct(
  17.         TranslatorInterface $tr
  18.     ) {
  19.         $this->tr $tr;
  20.     }
  21.     /**
  22.      * @return array
  23.      */
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             MenuConfigurationPageShipmentsEvent::NAME => 'onLoad',
  28.             MenuConfigurationPageEvent::NAME => 'onLoad2'
  29.         ];
  30.     }
  31.     /**
  32.      * @param MenuConfigurationPageShipmentsEvent $event
  33.      * @return void
  34.      */
  35.     public function onLoad(MenuConfigurationPageShipmentsEvent $event): void
  36.     {
  37.         $pages $event->getPages();
  38.         $pages[] = [
  39.             'id' => 'colissimo_bundle__configuration',
  40.             'name' => $this->tr->trans('Colissimo', [], 'ColissimoBundle')
  41.         ];
  42.         $event->setPages($pages);
  43.     }
  44.     /**
  45.      * @param MenuConfigurationPageEvent $event
  46.      * @return void
  47.      */
  48.     public function onLoad2(MenuConfigurationPageEvent $event): void
  49.     {
  50.         $pages $event->getPages();
  51.         $keyShipmentsMenu array_search('shipments_bundle__configuration'array_column($pages'id'));
  52.         if (is_numeric($keyShipmentsMenu)) {
  53.             $pages[$keyShipmentsMenu]['subpages'][] = ['id' => 'colissimo_bundle__configuration'];
  54.             $event->setPages($pages);
  55.         }
  56.     }
  57. }