Optimized for SPA

This commit is contained in:
Kevin Frantz
2019-01-05 23:52:37 +01:00
parent 9e685260e9
commit bccd6efaff
393 changed files with 253 additions and 37 deletions

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Translation\TranslatorInterface;
/**
* @author kevinfrantz
*/
abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private $translator;
const FORMAT_TYPES = [
'html',
'json',
'xml',
];
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
protected function generateShowDropdown(ItemInterface $menu, Event $event, string $route): void
{
$dropdown = $menu->addChild($this->trans('show'), [
'attributes' => [
'icon' => 'fas fa-eye',
'dropdown' => 'true',
],
]);
foreach (self::FORMAT_TYPES as $format) {
$dropdown->addChild($format, [
'route' => $route,
'routeParameters' => [
'id' => $this->getRequestId($event),
'_format' => $format,
],
'attributes' => [
'icon' => 'fas fa-sign-out-alt',
'divider_append' => true,
],
]);
}
$dropdown->addChild($this->trans('standard'), [
'route' => $route,
'routeParameters' => [
'id' => $this->getRequestId($event),
],
'attributes' => [
'icon' => 'fas fa-sign-out-alt',
],
]);
}
protected function trans(string $id, array $parameter = []): string
{
return $this->translator->trans($id, $parameter);
}
protected function getRequestId(Event $event): int
{
return $event->getRequest()->getCurrentRequest()->attributes->get('id');
}
}