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