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
*/
protected $translator;
private $translator;
const FORMAT_TYPES = [
'html',
@ -31,7 +31,7 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
protected function generateShowDropdown(ItemInterface $menu, Event $event,string $route): void
{
$dropdown = $menu->addChild($this->translator->trans('show'), [
$dropdown = $menu->addChild($this->trans('show'), [
'attributes' => [
'icon' => 'fas fa-eye',
'dropdown' => 'true'
@ -50,7 +50,7 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
]
]);
}
$dropdown->addChild($this->translator->trans('standard'), [
$dropdown->addChild($this->trans('standard'), [
'route' => $route,
'routeParameters' => [
'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
{

View File

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

View File

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