2018-09-06 09:44:29 +02:00
|
|
|
<?php
|
|
|
|
namespace App\Subscriber;
|
2018-09-13 00:24:49 +02:00
|
|
|
|
2018-09-06 09:44:29 +02:00
|
|
|
use App\Event\Menu\Topbar\UserMenuEvent;
|
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
|
|
|
use Symfony\Component\Translation\TranslatorInterface;
|
|
|
|
|
|
|
|
class UserMenuSubscriber implements EventSubscriberInterface
|
|
|
|
{
|
2018-09-06 11:02:22 +02:00
|
|
|
|
2018-09-06 09:44:29 +02:00
|
|
|
/**
|
2018-09-06 11:02:22 +02:00
|
|
|
*
|
2018-09-06 09:44:29 +02:00
|
|
|
* @var TokenStorageInterface
|
|
|
|
*/
|
|
|
|
private $tokenStorage;
|
2018-09-06 11:02:22 +02:00
|
|
|
|
2018-09-06 09:44:29 +02:00
|
|
|
/**
|
2018-09-06 11:02:22 +02:00
|
|
|
*
|
2018-09-06 09:44:29 +02:00
|
|
|
* @var TranslatorInterface
|
|
|
|
*/
|
|
|
|
private $translator;
|
2018-09-06 11:02:22 +02:00
|
|
|
|
2018-09-06 09:44:29 +02:00
|
|
|
public function __construct(TokenStorageInterface $tokenStorage, TranslatorInterface $translator)
|
|
|
|
{
|
|
|
|
$this->tokenStorage = $tokenStorage;
|
|
|
|
$this->translator = $translator;
|
|
|
|
}
|
2018-09-06 11:02:22 +02:00
|
|
|
|
|
|
|
public function onUserMenuConfigure(UserMenuEvent $event): void
|
2018-09-06 09:44:29 +02:00
|
|
|
{
|
|
|
|
$menu = $event->getItem();
|
2018-09-13 00:24:49 +02:00
|
|
|
$menu->addChild('start', [
|
|
|
|
'route' => 'homepage',
|
|
|
|
'attributes' => [
|
|
|
|
'icon' => 'fab fa-font-awesome-flag'
|
2018-09-06 11:02:22 +02:00
|
|
|
]
|
2018-09-13 00:24:49 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$menu->addChild('imprint', [
|
|
|
|
'route' => 'imprint',
|
|
|
|
'attributes' => [
|
|
|
|
'icon' => 'fas fa-address-card'
|
2018-09-06 11:02:22 +02:00
|
|
|
]
|
2018-09-13 00:24:49 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$dropdown = $menu->addChild('user', [
|
|
|
|
'attributes' => [
|
|
|
|
'dropdown' => true,
|
|
|
|
'icon' => 'fas fa-user'
|
2018-09-06 11:02:22 +02:00
|
|
|
]
|
2018-09-13 00:24:49 +02:00
|
|
|
]);
|
|
|
|
/**
|
|
|
|
* @todo replace the following check trough fos bundle
|
|
|
|
*/
|
|
|
|
if ($this->tokenStorage->getToken()->getRoles()) {
|
|
|
|
$dropdown->addChild('logout', [
|
2018-09-12 19:59:55 +02:00
|
|
|
'route' => 'logout',
|
2018-09-06 11:02:22 +02:00
|
|
|
'attributes' => [
|
2018-09-06 11:26:10 +02:00
|
|
|
'icon' => 'fas fa-sign-out-alt',
|
2018-09-13 00:24:49 +02:00
|
|
|
'divider_append' => true,
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$dropdown->addChild('login', [
|
|
|
|
'route' => 'login',
|
2018-09-06 11:02:22 +02:00
|
|
|
'attributes' => [
|
2018-09-13 00:24:49 +02:00
|
|
|
'divider_append' => true,
|
|
|
|
'icon' => 'fas fa-sign-in-alt'
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$dropdown->addChild('register', [
|
|
|
|
'route' => 'user_register',
|
|
|
|
'attributes' => [
|
|
|
|
'icon' => 'fas fa-file-signature'
|
2018-09-06 11:02:22 +02:00
|
|
|
]
|
2018-09-13 00:24:49 +02:00
|
|
|
]);
|
2018-09-06 09:44:29 +02:00
|
|
|
}
|
2018-09-06 11:02:22 +02:00
|
|
|
|
2018-09-06 09:44:29 +02:00
|
|
|
public static function getSubscribedEvents(): array
|
|
|
|
{
|
|
|
|
return [
|
2018-09-06 11:02:22 +02:00
|
|
|
UserMenuEvent::EVENT => 'onUserMenuConfigure'
|
2018-09-06 09:44:29 +02:00
|
|
|
];
|
|
|
|
}
|
2018-09-06 11:02:22 +02:00
|
|
|
}
|