Optimized user menu

This commit is contained in:
Kevin Frantz 2018-09-13 00:24:49 +02:00
parent e31386b908
commit 777b4aee61

View File

@ -1,5 +1,6 @@
<?php
namespace App\Subscriber;
use App\Event\Menu\Topbar\UserMenuEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@ -29,67 +30,52 @@ class UserMenuSubscriber implements EventSubscriberInterface
public function onUserMenuConfigure(UserMenuEvent $event): void
{
$menu = $event->getItem();
$menu->addChild(
'start',
[
'route' => 'homepage',
'attributes' => [
'icon' => 'fab fa-font-awesome-flag',
],
$menu->addChild('start', [
'route' => 'homepage',
'attributes' => [
'icon' => 'fab fa-font-awesome-flag'
]
);
$menu->addChild(
'imprint',
[
'route'=>'imprint',
'attributes' => [
'icon' => 'fas fa-address-card',
],
]);
$menu->addChild('imprint', [
'route' => 'imprint',
'attributes' => [
'icon' => 'fas fa-address-card'
]
);
$dropdown = $menu->addChild(
'user',
[
'attributes' => [
'dropdown' => true,
'icon' => 'fas fa-user',
],
]);
$dropdown = $menu->addChild('user', [
'attributes' => [
'dropdown' => true,
'icon' => 'fas fa-user'
]
);
$dropdown->addChild(
'login',
[
'route' => 'login',
'attributes' => [
'divider_append' => true,
'icon' => 'fas fa-sign-in-alt',
],
]
);
$dropdown->addChild(
'logout',
[
]);
/**
* @todo replace the following check trough fos bundle
*/
if ($this->tokenStorage->getToken()->getRoles()) {
$dropdown->addChild('logout', [
'route' => 'logout',
'attributes' => [
'icon' => 'fas fa-sign-out-alt',
],
]
);
$dropdown->addChild(
'register',
[
'route' => 'user_register',
'divider_append' => true,
]
]);
} else {
$dropdown->addChild('login', [
'route' => 'login',
'attributes' => [
'divider_prepend' => true,
'icon' => 'fas fa-file-signature',
],
'divider_append' => true,
'icon' => 'fas fa-sign-in-alt'
]
]);
}
$dropdown->addChild('register', [
'route' => 'user_register',
'attributes' => [
'icon' => 'fas fa-file-signature'
]
);
]);
}
public static function getSubscribedEvents(): array