From 1915c77d8cf141cafe7a19353873ceaae9f3c950 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 20 Sep 2018 14:48:37 +0200 Subject: [PATCH] Implemented different formats --- .../src/Subscriber/SourceMenuSubscriber.php | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/application/src/Subscriber/SourceMenuSubscriber.php b/application/src/Subscriber/SourceMenuSubscriber.php index 2c4a00e..345e654 100644 --- a/application/src/Subscriber/SourceMenuSubscriber.php +++ b/application/src/Subscriber/SourceMenuSubscriber.php @@ -6,6 +6,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Translation\TranslatorInterface; use App\Event\Menu\Topbar\SourceMenuEvent; +use Knp\Menu\ItemInterface; class SourceMenuSubscriber implements EventSubscriberInterface { @@ -30,16 +31,48 @@ class SourceMenuSubscriber implements EventSubscriberInterface $menu = $event->getItem(); $menu->addChild($this->translator->trans('edit'), [ 'route' => 'app_source_edit', - 'routeParameters' => ['id' => $event->getRequest()->getCurrentRequest()->attributes->get('id')], + 'routeParameters' => [ + 'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'), + ], 'attributes' => [ 'icon' => 'fas fa-edit', ], ]); - $menu->addChild($this->translator->trans('show'), [ - 'route' => 'app_source_show', - 'routeParameters' => ['id' => $event->getRequest()->getCurrentRequest()->attributes->get('id')], + $this->generateSourceFormatDropdown($menu, $event); + } + + private function generateSourceFormatDropdown(ItemInterface $menu, SourceMenuEvent $event): void + { + $dropdown = $menu->addChild($this->translator->trans('show'), [ 'attributes' => [ 'icon' => 'fas fa-eye', + 'dropdown' => 'true', + ], + ]); + foreach ([ + 'html', + 'json', + 'xml', + ] as $format) { + $dropdown->addChild($format, [ + 'route' => 'app_source_show', + 'routeParameters' => [ + 'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'), + '_format' => $format, + ], + 'attributes' => [ + 'icon' => 'fas fa-sign-out-alt', + 'divider_append' => true, + ], + ]); + } + $dropdown->addChild($this->translator->trans('standard'), [ + 'route' => 'app_source_show', + 'routeParameters' => [ + 'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'), + ], + 'attributes' => [ + 'icon' => 'fas fa-sign-out-alt', ], ]); }