Implemented different formats

This commit is contained in:
Kevin Frantz 2018-09-20 14:48:37 +02:00
parent 3bf84d3ec8
commit 1915c77d8c

View File

@ -6,6 +6,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Translation\TranslatorInterface;
use App\Event\Menu\Topbar\SourceMenuEvent; use App\Event\Menu\Topbar\SourceMenuEvent;
use Knp\Menu\ItemInterface;
class SourceMenuSubscriber implements EventSubscriberInterface class SourceMenuSubscriber implements EventSubscriberInterface
{ {
@ -30,16 +31,48 @@ class SourceMenuSubscriber implements EventSubscriberInterface
$menu = $event->getItem(); $menu = $event->getItem();
$menu->addChild($this->translator->trans('edit'), [ $menu->addChild($this->translator->trans('edit'), [
'route' => 'app_source_edit', 'route' => 'app_source_edit',
'routeParameters' => ['id' => $event->getRequest()->getCurrentRequest()->attributes->get('id')], 'routeParameters' => [
'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'),
],
'attributes' => [ 'attributes' => [
'icon' => 'fas fa-edit', 'icon' => 'fas fa-edit',
], ],
]); ]);
$menu->addChild($this->translator->trans('show'), [ $this->generateSourceFormatDropdown($menu, $event);
'route' => 'app_source_show', }
'routeParameters' => ['id' => $event->getRequest()->getCurrentRequest()->attributes->get('id')],
private function generateSourceFormatDropdown(ItemInterface $menu, SourceMenuEvent $event): void
{
$dropdown = $menu->addChild($this->translator->trans('show'), [
'attributes' => [ 'attributes' => [
'icon' => 'fas fa-eye', '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',
], ],
]); ]);
} }