mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 17:29:04 +00:00 
			
		
		
		
	Substituted old menu trough KNP menu bundle
This commit is contained in:
		| @@ -17,7 +17,7 @@ class DefaultController extends AbstractController implements DefaultControllerI | ||||
|      */ | ||||
|     public function imprint(): Response | ||||
|     { | ||||
|         return $this->render("standard/imprint.html.twig",['menu_items'=>[]]); | ||||
|         return $this->render("standard/imprint.html.twig"); | ||||
|     } | ||||
|      | ||||
|     /** | ||||
| @@ -25,7 +25,7 @@ class DefaultController extends AbstractController implements DefaultControllerI | ||||
|      */ | ||||
|     public function homepage(): Response | ||||
|     { | ||||
|         return $this->render("standard/homepage.html.twig",['menu_items'=>[]]); | ||||
|         return $this->render("standard/homepage.html.twig"); | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -17,7 +17,7 @@ class UserController extends AbstractController implements UserControllerInterfa | ||||
|      */ | ||||
|     public function logout(): Response | ||||
|     { | ||||
|         return $this->render("user/login.html.twig",['menu_items'=>[]]); | ||||
|         return $this->render("user/login.html.twig"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -25,7 +25,7 @@ class UserController extends AbstractController implements UserControllerInterfa | ||||
|      */ | ||||
|     public function login(): Response | ||||
|     { | ||||
|         return $this->render("user/login.html.twig",['menu_items'=>[]]); | ||||
|         return $this->render("user/login.html.twig"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -33,7 +33,6 @@ class UserController extends AbstractController implements UserControllerInterfa | ||||
|      */ | ||||
|     public function register(): Response | ||||
|     { | ||||
|         return $this->render("user/register.html.twig",['menu_items'=>[]]); | ||||
|         return $this->render("user/register.html.twig"); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -30,7 +30,11 @@ class Menu | ||||
|      | ||||
|     public function userTopbar(RequestStack $request): ItemInterface | ||||
|     { | ||||
|         $menu = $this->factory->createItem('root'); | ||||
|         $menu = $this->factory->createItem('root', array( | ||||
|             'childrenAttributes'    => array( | ||||
|                 'class'             => 'navbar-nav mr-auto', | ||||
|             ), | ||||
|         )); | ||||
|          | ||||
|         $this->dispatcher->dispatch( | ||||
|             UserMenuEvent::EVENT, | ||||
|   | ||||
| @@ -1,9 +1,5 @@ | ||||
| <?php | ||||
| // src/Subscriber/UserMenuSubscriber.php | ||||
|  | ||||
| namespace App\Subscriber; | ||||
|  | ||||
| use App\Entity\User; | ||||
| use App\Event\Menu\Topbar\UserMenuEvent; | ||||
| use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||||
| use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||||
| @@ -11,44 +7,91 @@ 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) | ||||
|  | ||||
|     public function onUserMenuConfigure(UserMenuEvent $event): void | ||||
|     { | ||||
|         $menu = $event->getItem(); | ||||
|         /** @var User $user */ | ||||
|         $user = $this->tokenStorage->getToken()->getUser(); | ||||
|   | ||||
|         $dropdown = $menu->addChild( | ||||
|             $this->translator->trans('Hello %username%', ['%username%' => 'Noname'], 'usermenu'), | ||||
|             ['dropdown' => true] | ||||
|         $menu->addChild( | ||||
|             'linking', | ||||
|             [ | ||||
|                 'route' => 'homepage', | ||||
|             ] | ||||
|             ); | ||||
|          | ||||
|  | ||||
|         $menu->addChild( | ||||
|             'texting', | ||||
|             [ | ||||
|                 'labelAttributes' => [ | ||||
|                     'class' => 'class3 class4', | ||||
|                 ], | ||||
|             ] | ||||
|             ); | ||||
|  | ||||
|         $dropdown = $menu->addChild( | ||||
|             'Hello Me', | ||||
|             [ | ||||
|                 'attributes' => [ | ||||
|                     'dropdown' => true, | ||||
|                 ], | ||||
|             ] | ||||
|             ); | ||||
|  | ||||
|         $dropdown->addChild( | ||||
|             $this->translator->trans('Login', [], 'usermenu'), | ||||
|             ['route' => 'user_login'] | ||||
|             'Profile', | ||||
|             [ | ||||
|                 'route' => 'homepage', | ||||
|                 'attributes' => [ | ||||
|                     'divider_append' => true, | ||||
|                 ], | ||||
|             ] | ||||
|             ); | ||||
|  | ||||
|         $dropdown->addChild( | ||||
|             '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', | ||||
|                 ], | ||||
|             ] | ||||
|             ); | ||||
|     } | ||||
|      | ||||
|  | ||||
|     public static function getSubscribedEvents(): array | ||||
|     { | ||||
|         return [ | ||||
|             UserMenuEvent::EVENT => 'onUserMenuConfigure', | ||||
|             UserMenuEvent::EVENT => 'onUserMenuConfigure' | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user