From 5c2a45b467f15f74cc96f1336c176f1bdf15e210 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 4 Oct 2018 22:39:26 +0200 Subject: [PATCH] Added node menu --- application/src/Controller/NodeController.php | 18 ++++++++++ .../AbstractEntityMenuSubscriber.php | 2 +- .../src/Subscriber/NodeMenuSubscriber.php | 34 +++++++++++++++++++ .../src/Subscriber/SourceMenuSubscriber.php | 4 +-- .../structure/navbar/node_sub.html.twig | 11 ++++++ application/templates/node/node.html.twig | 3 ++ 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 application/templates/frames/structure/navbar/node_sub.html.twig diff --git a/application/src/Controller/NodeController.php b/application/src/Controller/NodeController.php index 47a73c6..5e456b0 100644 --- a/application/src/Controller/NodeController.php +++ b/application/src/Controller/NodeController.php @@ -40,6 +40,24 @@ class NodeController extends AbstractEntityController return $this->redirectToRouteById('app_law_show',$lawId); } + /** + * @Route("/node/{id}/parents.{_format}", defaults={"_format"="html"}) + */ + public function parents(int $id):Response{ + /** + * @todo Implement + */ + } + + /** + * @Route("/node/{id}/childs.{_format}", defaults={"_format"="html"}) + */ + public function childs(int $id):Response{ + /** + * @todo Implement + */ + } + protected function setEntityName(): void { $this->entityName = Node::class; diff --git a/application/src/Subscriber/AbstractEntityMenuSubscriber.php b/application/src/Subscriber/AbstractEntityMenuSubscriber.php index dcccd7e..65bdfec 100644 --- a/application/src/Subscriber/AbstractEntityMenuSubscriber.php +++ b/application/src/Subscriber/AbstractEntityMenuSubscriber.php @@ -61,7 +61,7 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface ]); } - private function getRequestId(Event $event): int + protected function getRequestId(Event $event): int { return $event->getRequest()->getCurrentRequest()->attributes->get('id'); } diff --git a/application/src/Subscriber/NodeMenuSubscriber.php b/application/src/Subscriber/NodeMenuSubscriber.php index 27c7c94..d6c2b73 100644 --- a/application/src/Subscriber/NodeMenuSubscriber.php +++ b/application/src/Subscriber/NodeMenuSubscriber.php @@ -2,6 +2,7 @@ namespace App\Subscriber; use App\DBAL\Types\MenuEventType; +use App\Event\Menu\MenuEvent; /** * @@ -10,6 +11,39 @@ use App\DBAL\Types\MenuEventType; */ class NodeMenuSubscriber extends AbstractEntityMenuSubscriber { + public function onNodeMenuConfigure(MenuEvent $event): void + { + $menu = $event->getItem(); + $this->generateShowDropdown($menu, $event,'app_source_show'); + $menu->addChild($this->translator->trans('law'), [ + 'route' => 'app_node_law', + 'routeParameters' => [ + 'id' => $this->getRequestId($event), + ], + 'attributes' => [ + 'icon' => 'fa fa-gavel', + ], + ]); + $menu->addChild($this->translator->trans('parents'), [ + 'route' => 'app_node_parents', + 'routeParameters' => [ + 'id' => $this->getRequestId($event), + ], + 'attributes' => [ + 'icon' => 'fa fa-female', + ], + ]); + $menu->addChild($this->translator->trans('childs'), [ + 'route' => 'app_node_childs', + 'routeParameters' => [ + 'id' => $this->getRequestId($event), + ], + 'attributes' => [ + 'icon' => 'fa fa-child', + ], + ]); + } + public static function getSubscribedEvents() { return [ diff --git a/application/src/Subscriber/SourceMenuSubscriber.php b/application/src/Subscriber/SourceMenuSubscriber.php index 6d7b4a1..1eaaad4 100644 --- a/application/src/Subscriber/SourceMenuSubscriber.php +++ b/application/src/Subscriber/SourceMenuSubscriber.php @@ -13,7 +13,7 @@ class SourceMenuSubscriber extends AbstractEntityMenuSubscriber $menu->addChild($this->translator->trans('edit'), [ 'route' => 'app_source_edit', 'routeParameters' => [ - 'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'), + 'id' => $this->getRequestId($event), ], 'attributes' => [ 'icon' => 'fas fa-edit', @@ -23,7 +23,7 @@ class SourceMenuSubscriber extends AbstractEntityMenuSubscriber $menu->addChild($this->translator->trans('node'), [ 'route' => 'app_source_node', 'routeParameters' => [ - 'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'), + 'id' => $this->getRequestId($event), ], 'attributes' => [ 'icon' => 'fas fa-globe', diff --git a/application/templates/frames/structure/navbar/node_sub.html.twig b/application/templates/frames/structure/navbar/node_sub.html.twig new file mode 100644 index 0000000..0afb272 --- /dev/null +++ b/application/templates/frames/structure/navbar/node_sub.html.twig @@ -0,0 +1,11 @@ + diff --git a/application/templates/node/node.html.twig b/application/templates/node/node.html.twig index e1d49a7..775430b 100644 --- a/application/templates/node/node.html.twig +++ b/application/templates/node/node.html.twig @@ -3,4 +3,7 @@ {% trans %} Node {% endtrans %} +{% endblock %} +{% block sub_navigation %} + {% include 'frames/structure/navbar/node_sub.html.twig'%} {% endblock %} \ No newline at end of file