2018-09-06 09:44:29 +02:00
|
|
|
<?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
|
|
|
|
{
|
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-06 11:02:22 +02:00
|
|
|
$menu->addChild(
|
|
|
|
'linking',
|
|
|
|
[
|
|
|
|
'route' => 'homepage',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$menu->addChild(
|
|
|
|
'texting',
|
|
|
|
[
|
|
|
|
'labelAttributes' => [
|
|
|
|
'class' => 'class3 class4',
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2018-09-06 09:44:29 +02:00
|
|
|
$dropdown = $menu->addChild(
|
2018-09-06 11:02:22 +02:00
|
|
|
'Hello Me',
|
|
|
|
[
|
|
|
|
'attributes' => [
|
|
|
|
'dropdown' => true,
|
|
|
|
],
|
|
|
|
]
|
2018-09-06 09:44:29 +02:00
|
|
|
);
|
2018-09-06 11:02:22 +02:00
|
|
|
|
|
|
|
$dropdown->addChild(
|
|
|
|
'Profile',
|
|
|
|
[
|
|
|
|
'route' => 'homepage',
|
|
|
|
'attributes' => [
|
|
|
|
'divider_append' => true,
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2018-09-06 09:44:29 +02:00
|
|
|
$dropdown->addChild(
|
2018-09-06 11:02:22 +02:00
|
|
|
'text',
|
|
|
|
[
|
|
|
|
'attributes' => [
|
|
|
|
'icon' => 'fa fa-user-circle',
|
|
|
|
],
|
|
|
|
'labelAttributes' => [
|
|
|
|
'class' => ['class1', 'class2'],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$dropdown->addChild(
|
|
|
|
'Logout',
|
|
|
|
[
|
|
|
|
'route' => 'user_logout',
|
|
|
|
'attributes' => [
|
|
|
|
'divider_prepend' => true,
|
|
|
|
'icon' => 'fa fa-sign-out',
|
|
|
|
],
|
|
|
|
]
|
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
|
|
|
}
|