Implement site-wide page header
This commit is contained in:
32
src/EventSubscriber/TwigEventSubscriber.php
Normal file
32
src/EventSubscriber/TwigEventSubscriber.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventSubscriber;
|
||||
|
||||
use App\Repository\ConferenceRepository;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\ControllerEvent;
|
||||
use Twig\Environment;
|
||||
|
||||
class TwigEventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $twig;
|
||||
private $conferenceRepository;
|
||||
|
||||
public function __construct(Environment $twig, ConferenceRepository $conferenceRepository)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
$this->conferenceRepository = $conferenceRepository;
|
||||
}
|
||||
|
||||
public function onControllerEvent(ControllerEvent $event): void
|
||||
{
|
||||
$this->twig->addGlobal('conferences', $this->conferenceRepository->findAll());
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
ControllerEvent::class => 'onControllerEvent',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user