src/Listener/DtvNavigationListener.php line 30

Open in your IDE?
  1. <?php
  2.     namespace App\Listener;
  3.     use Symfony\Component\HttpKernel\Event\ControllerEvent;
  4.     use Twig\Environment;
  5.     /**
  6.      * Listener qui permet d'ajouter la class ACTIVE dans le secondary navigation à partir de la route dans BO DTV
  7.      */
  8.     class DtvNavigationListener
  9.     {
  10.         private Environment $twig;
  11.         /**
  12.          * @param Environment $twig
  13.          */
  14.         public function __constructEnvironment $twig )
  15.         {
  16.             $this->twig $twig;
  17.         }
  18.         /**
  19.          * @param ControllerEvent $event
  20.          *
  21.          * @return void
  22.          */
  23.         public function onKernelControllerControllerEvent $event ): void
  24.         {
  25.             $currentRoute $event->getRequest()->get'_route' );
  26.             if ( str_contains$currentRoute'dtv_back_platform' ) ) {
  27.                 $re  '/dtv_back_platform_([a-zA-Z]*)_(.*)/m';
  28.                 $str $currentRoute;
  29.                 preg_match_all$re$str$matchesPREG_SET_ORDER );
  30.                 $this->twig->addGlobal'secondary'$matches][ ] );
  31.             } else {
  32.                 $this->twig->addGlobal'secondary''' );
  33.             }
  34.         }
  35.     }