2018-09-20 14:26:28 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Subscriber;
|
|
|
|
|
|
|
|
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;
|
2018-09-20 14:48:37 +02:00
|
|
|
use Knp\Menu\ItemInterface;
|
2018-09-20 14:26:28 +02:00
|
|
|
|
|
|
|
class SourceMenuSubscriber implements EventSubscriberInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var TokenStorageInterface
|
|
|
|
*/
|
|
|
|
private $tokenStorage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var TranslatorInterface
|
|
|
|
*/
|
|
|
|
private $translator;
|
|
|
|
|
|
|
|
public function __construct(TokenStorageInterface $tokenStorage, TranslatorInterface $translator)
|
|
|
|
{
|
|
|
|
$this->tokenStorage = $tokenStorage;
|
|
|
|
$this->translator = $translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onSourceMenuConfigure(SourceMenuEvent $event): void
|
|
|
|
{
|
|
|
|
$menu = $event->getItem();
|
|
|
|
$menu->addChild($this->translator->trans('edit'), [
|
|
|
|
'route' => 'app_source_edit',
|
2018-09-20 14:48:37 +02:00
|
|
|
'routeParameters' => [
|
|
|
|
'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'),
|
|
|
|
],
|
2018-09-20 14:26:28 +02:00
|
|
|
'attributes' => [
|
|
|
|
'icon' => 'fas fa-edit',
|
|
|
|
],
|
|
|
|
]);
|
2018-09-20 14:48:37 +02:00
|
|
|
$this->generateSourceFormatDropdown($menu, $event);
|
2018-09-20 16:03:00 +02:00
|
|
|
$menu->addChild($this->translator->trans('node'), [
|
|
|
|
'route' => 'app_source_node',
|
|
|
|
'routeParameters' => [
|
|
|
|
'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'),
|
|
|
|
],
|
|
|
|
'attributes' => [
|
|
|
|
'icon' => 'fas fa-globe',
|
|
|
|
],
|
|
|
|
]);
|
2018-09-20 14:48:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function generateSourceFormatDropdown(ItemInterface $menu, SourceMenuEvent $event): void
|
|
|
|
{
|
|
|
|
$dropdown = $menu->addChild($this->translator->trans('show'), [
|
2018-09-20 14:26:28 +02:00
|
|
|
'attributes' => [
|
|
|
|
'icon' => 'fas fa-eye',
|
2018-09-20 14:48:37 +02:00
|
|
|
'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',
|
2018-09-20 14:26:28 +02:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getSubscribedEvents(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
SourceMenuEvent::EVENT => 'onSourceMenuConfigure',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|