infinito/application/src/Subscriber/UserMenuSubscriber.php

102 lines
2.5 KiB
PHP
Raw Normal View History

<?php
namespace App\Subscriber;
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
{
/**
*
* @var TokenStorageInterface
*/
private $tokenStorage;
/**
*
* @var TranslatorInterface
*/
private $translator;
public function __construct(TokenStorageInterface $tokenStorage, TranslatorInterface $translator)
{
$this->tokenStorage = $tokenStorage;
$this->translator = $translator;
}
public function onUserMenuConfigure(UserMenuEvent $event): void
{
$menu = $event->getItem();
$menu->addChild(
2018-09-06 11:26:10 +02:00
'start',
[
'route' => 'homepage',
2018-09-06 11:26:10 +02:00
'attributes' => [
'icon' => 'fab fa-font-awesome-flag',
],
]
);
$menu->addChild(
2018-09-06 11:26:10 +02:00
'imprint',
[
2018-09-06 11:26:10 +02:00
'route'=>'imprint',
'attributes' => [
'icon' => 'fas fa-address-card',
],
]
);
$dropdown = $menu->addChild(
2018-09-06 11:26:10 +02:00
'user',
[
'attributes' => [
'dropdown' => true,
2018-09-06 11:26:10 +02:00
'icon' => 'fas fa-user',
],
]
);
$dropdown->addChild(
2018-09-06 11:26:10 +02:00
'login',
[
'route' => 'login',
'attributes' => [
'divider_append' => true,
2018-09-06 11:26:10 +02:00
'icon' => 'fas fa-sign-in-alt',
],
]
);
$dropdown->addChild(
2018-09-06 11:26:10 +02:00
'logout',
[
2018-09-06 11:26:10 +02:00
'route' => 'user_logout',
'attributes' => [
2018-09-06 11:26:10 +02:00
'icon' => 'fas fa-sign-out-alt',
],
]
);
$dropdown->addChild(
2018-09-06 11:26:10 +02:00
'register',
[
2018-09-06 11:26:10 +02:00
'route' => 'user_register',
'attributes' => [
'divider_prepend' => true,
2018-09-06 11:26:10 +02:00
'icon' => 'fas fa-file-signature',
],
]
);
}
public static function getSubscribedEvents(): array
{
return [
UserMenuEvent::EVENT => 'onUserMenuConfigure'
];
}
}