Added shortcut for trans

This commit is contained in:
Kevin Frantz 2018-10-04 22:45:51 +02:00
parent 5c2a45b467
commit 8de52474a5
3 changed files with 12 additions and 8 deletions

View File

@ -16,7 +16,7 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
/** /**
* @var TranslatorInterface * @var TranslatorInterface
*/ */
protected $translator; private $translator;
const FORMAT_TYPES = [ const FORMAT_TYPES = [
'html', 'html',
@ -31,7 +31,7 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
protected function generateShowDropdown(ItemInterface $menu, Event $event,string $route): void protected function generateShowDropdown(ItemInterface $menu, Event $event,string $route): void
{ {
$dropdown = $menu->addChild($this->translator->trans('show'), [ $dropdown = $menu->addChild($this->trans('show'), [
'attributes' => [ 'attributes' => [
'icon' => 'fas fa-eye', 'icon' => 'fas fa-eye',
'dropdown' => 'true' 'dropdown' => 'true'
@ -50,7 +50,7 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
] ]
]); ]);
} }
$dropdown->addChild($this->translator->trans('standard'), [ $dropdown->addChild($this->trans('standard'), [
'route' => $route, 'route' => $route,
'routeParameters' => [ 'routeParameters' => [
'id' => $this->getRequestId($event) 'id' => $this->getRequestId($event)
@ -60,6 +60,10 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
] ]
]); ]);
} }
protected function trans(string $id, array $parameter=[]):string{
return $this->translator->trans($id,$parameter);
}
protected function getRequestId(Event $event): int protected function getRequestId(Event $event): int
{ {

View File

@ -15,7 +15,7 @@ class NodeMenuSubscriber extends AbstractEntityMenuSubscriber
{ {
$menu = $event->getItem(); $menu = $event->getItem();
$this->generateShowDropdown($menu, $event,'app_source_show'); $this->generateShowDropdown($menu, $event,'app_source_show');
$menu->addChild($this->translator->trans('law'), [ $menu->addChild($this->trans('law'), [
'route' => 'app_node_law', 'route' => 'app_node_law',
'routeParameters' => [ 'routeParameters' => [
'id' => $this->getRequestId($event), 'id' => $this->getRequestId($event),
@ -24,7 +24,7 @@ class NodeMenuSubscriber extends AbstractEntityMenuSubscriber
'icon' => 'fa fa-gavel', 'icon' => 'fa fa-gavel',
], ],
]); ]);
$menu->addChild($this->translator->trans('parents'), [ $menu->addChild($this->trans('parents'), [
'route' => 'app_node_parents', 'route' => 'app_node_parents',
'routeParameters' => [ 'routeParameters' => [
'id' => $this->getRequestId($event), 'id' => $this->getRequestId($event),
@ -33,7 +33,7 @@ class NodeMenuSubscriber extends AbstractEntityMenuSubscriber
'icon' => 'fa fa-female', 'icon' => 'fa fa-female',
], ],
]); ]);
$menu->addChild($this->translator->trans('childs'), [ $menu->addChild($this->trans('childs'), [
'route' => 'app_node_childs', 'route' => 'app_node_childs',
'routeParameters' => [ 'routeParameters' => [
'id' => $this->getRequestId($event), 'id' => $this->getRequestId($event),

View File

@ -10,7 +10,7 @@ class SourceMenuSubscriber extends AbstractEntityMenuSubscriber
public function onSourceMenuConfigure(MenuEvent $event): void public function onSourceMenuConfigure(MenuEvent $event): void
{ {
$menu = $event->getItem(); $menu = $event->getItem();
$menu->addChild($this->translator->trans('edit'), [ $menu->addChild($this->trans('edit'), [
'route' => 'app_source_edit', 'route' => 'app_source_edit',
'routeParameters' => [ 'routeParameters' => [
'id' => $this->getRequestId($event), 'id' => $this->getRequestId($event),
@ -20,7 +20,7 @@ class SourceMenuSubscriber extends AbstractEntityMenuSubscriber
], ],
]); ]);
$this->generateShowDropdown($menu, $event,'app_source_show'); $this->generateShowDropdown($menu, $event,'app_source_show');
$menu->addChild($this->translator->trans('node'), [ $menu->addChild($this->trans('node'), [
'route' => 'app_source_node', 'route' => 'app_source_node',
'routeParameters' => [ 'routeParameters' => [
'id' => $this->getRequestId($event), 'id' => $this->getRequestId($event),