Optimized UserMenuSubscriber

This commit is contained in:
Kevin Frantz
2019-03-29 16:53:01 +01:00
parent 65624946d4
commit 522ba1994e
4 changed files with 104 additions and 68 deletions

View File

@@ -11,6 +11,8 @@ use Symfony\Component\HttpFoundation\Request;
use FOS\RestBundle\Request\ParameterBag;
/**
* This class is just a result of refactoring. Feel free to replace it.
*
* @author kevinfrantz
*/
abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
@@ -35,9 +37,9 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
*/
protected function generateShowDropdown(ItemInterface $menu, Event $event, string $route): void
{
$dropdown = $menu->addChild($this->trans('show'), [
$dropdown = $menu->addChild($this->trans('format'), [
'attributes' => [
'icon' => 'fas fa-eye',
'icon' => 'fas fa-file',
'dropdown' => 'true',
],
]);
@@ -71,16 +73,6 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface
return $this->translator->trans($id, $parameter);
}
/**
* @param Event $event
*
* @return int|string
*/
protected function getRequestIdentity(Event $event)
{
return $this->getRequestAttributs($event)->get('identity');
}
/**
* @param Event $event
*

View File

@@ -42,14 +42,14 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
public function onUserMenuConfigure(MenuEvent $event): void
{
$menu = $event->getItem();
$menu->addChild($this->translator->trans('start'), [
$menu->addChild($this->trans('start'), [
'route' => 'homepage',
'attributes' => [
'icon' => 'fab fa-font-awesome-flag',
],
]);
$menu->addChild($this->translator->trans('imprint'), [
$menu->addChild($this->trans('imprint'), [
'uri' => '/api/rest/source/'.strtolower(ImpressumFixtureSource::SLUG).'.html',
'attributes' => [
'icon' => 'fas fa-address-card',
@@ -76,7 +76,7 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
{
$token = $this->getToken();
return ($token) ? $token->getUsername() : 'user';
return ($token) ? $token->getUsername() : $this->trans('user');
}
/**
@@ -101,14 +101,14 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
],
]);
if ($this->getRoles()) {
$dropdown->addChild($this->translator->trans('logout'), [
$dropdown->addChild($this->trans('logout'), [
'route' => 'logout',
'attributes' => [
'icon' => 'fas fa-sign-out-alt',
'divider_append' => true,
],
]);
$dropdown->addChild($this->translator->trans('edit profile'), [
$dropdown->addChild($this->trans('edit profile'), [
'route' => 'fos_user_profile_edit',
'attributes' => [
'icon' => 'fas fa-user-edit',
@@ -116,20 +116,20 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
],
]);
} else {
$dropdown->addChild($this->translator->trans('login'), [
$dropdown->addChild($this->trans('login'), [
'route' => 'fos_user_security_login',
'attributes' => [
'divider_append' => true,
'icon' => 'fas fa-sign-in-alt',
],
]);
$dropdown->addChild('register', [
'route' => 'fos_user_registration_register',
'attributes' => [
'icon' => 'fas fa-file-signature',
],
]);
}
$dropdown->addChild('register', [
'route' => 'fos_user_registration_register',
'attributes' => [
'icon' => 'fas fa-file-signature',
],
]);
}
/**