1515use KevinPapst \TablerBundle \Helper \ContextHelper ;
1616use KevinPapst \TablerBundle \Model \MenuItemInterface ;
1717use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
18- use Symfony \Component \HttpFoundation \Request ;
18+ use Symfony \Component \HttpFoundation \RequestStack ;
1919use Twig \Extension \RuntimeExtensionInterface ;
2020
2121final class RuntimeExtension implements RuntimeExtensionInterface
@@ -25,6 +25,7 @@ final class RuntimeExtension implements RuntimeExtensionInterface
2525 * @param array<string, string> $icons
2626 */
2727 public function __construct (
28+ private readonly RequestStack $ requestStack ,
2829 private readonly EventDispatcherInterface $ eventDispatcher ,
2930 private readonly ContextHelper $ helper ,
3031 private readonly array $ routes ,
@@ -66,16 +67,19 @@ public function containerClass(string $class = ''): string
6667 }
6768
6869 /**
69- * @param Request $request
70- *
7170 * @return MenuItemInterface[]|null
7271 */
73- public function getMenu (Request $ request ): ?array
72+ public function getMenu (): ?array
7473 {
7574 if (!$ this ->eventDispatcher ->hasListeners (MenuEvent::class)) {
7675 return null ;
7776 }
7877
78+ $ request = $ this ->requestStack ->getCurrentRequest ();
79+ if ($ request === null ) {
80+ return null ;
81+ }
82+
7983 /** @var MenuEvent $event */
8084 $ event = $ this ->eventDispatcher ->dispatch (new MenuEvent ($ request ));
8185
0 commit comments