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 __construct( Environment $twig )
  15. {
  16. $this->twig = $twig;
  17. }
  18. /**
  19. * @param ControllerEvent $event
  20. *
  21. * @return void
  22. */
  23. public function onKernelController( ControllerEvent $event ): void
  24. {
  25. $currentRoute = $event->getRequest()->get( '_route' );
  26. if($currentRoute && str_contains( $currentRoute, 'dtv_back_platform' ))
  27. {
  28. $re = '/dtv_back_platform_([a-zA-Z]*)_(.*)/m';
  29. $str = $currentRoute;
  30. preg_match_all( $re, $str, $matches, PREG_SET_ORDER );
  31. $this->twig->addGlobal( 'secondary', $matches[ 0 ][ 1 ] );
  32. } else {
  33. $this->twig->addGlobal( 'secondary', '' );
  34. }
  35. }
  36. }