<?php
namespace App\Listener;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Twig\Environment;
/**
* Listener qui permet d'ajouter la class ACTIVE dans le secondary navigation à partir de la route dans BO DTV
*/
class DtvNavigationListener
{
private Environment $twig;
/**
* @param Environment $twig
*/
public function __construct( Environment $twig )
{
$this->twig = $twig;
}
/**
* @param ControllerEvent $event
*
* @return void
*/
public function onKernelController( ControllerEvent $event ): void
{
$currentRoute = $event->getRequest()->get( '_route' );
if($currentRoute && str_contains( $currentRoute, 'dtv_back_platform' ))
{
$re = '/dtv_back_platform_([a-zA-Z]*)_(.*)/m';
$str = $currentRoute;
preg_match_all( $re, $str, $matches, PREG_SET_ORDER );
$this->twig->addGlobal( 'secondary', $matches[ 0 ][ 1 ] );
} else {
$this->twig->addGlobal( 'secondary', '' );
}
}
}