Browse code

Update

Benjamin Roth authored on17/08/2023 00:07:19
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,63 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of contao-weinanlieferung-bundle.
7
+ *
8
+ * (c) vonRotenberg
9
+ *
10
+ * @license commercial
11
+ */
12
+
13
+namespace vonRotenberg\WeinanlieferungBundle\EventListener\Backend;
14
+
15
+
16
+
17
+use Contao\CoreBundle\Event\MenuEvent;
18
+use Symfony\Component\HttpFoundation\RequestStack;
19
+use Symfony\Component\Routing\RouterInterface;
20
+use Terminal42\ServiceAnnotationBundle\Annotation\ServiceTag;
21
+use vonRotenberg\WeinanlieferungBundle\Controller\Backend\WeinanlieferungBookingsController;
22
+
23
+/**
24
+ * @ServiceTag("kernel.event_listener", event="contao.backend_menu_build", priority=-255)
25
+ */
26
+ class BackendMenuListener
27
+{
28
+     protected $router;
29
+     protected $requestStack;
30
+
31
+     public function __construct(RouterInterface $router, RequestStack $requestStack)
32
+     {
33
+         $this->router = $router;
34
+         $this->requestStack = $requestStack;
35
+     }
36
+
37
+     public function __invoke(MenuEvent $event): void
38
+     {
39
+         $factory = $event->getFactory();
40
+         $tree = $event->getTree();
41
+         $ref = $this->requestStack->getCurrentRequest()->attributes->get('_contao_referer_id');
42
+
43
+         if ('mainMenu' !== $tree->getName()) {
44
+             return;
45
+         }
46
+
47
+         if (($contentNode = $tree->getChild('weinanlieferung')) === null)
48
+         {
49
+             $contentNode = $tree->addChild('weinanlieferung');
50
+         }
51
+
52
+         $node = $factory
53
+             ->createItem('booking-list')
54
+             ->setUri($this->router->generate(WeinanlieferungBookingsController::class,['ref'=>$ref]))
55
+             ->setLabel('Buchungsübersicht')
56
+             ->setLinkAttribute('title', 'Übersicht aller gebuchter Anlieferungszeiten')
57
+             ->setLinkAttribute('class', 'navigation wa-booking-list')
58
+             ->setCurrent($this->requestStack->getCurrentRequest()->get('_controller') === WeinanlieferungBookingsController::class)
59
+         ;
60
+
61
+         $contentNode->addChild($node);
62
+     }
63
+}