mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 01:09:41 +00:00 
			
		
		
		
	Added draft for user menu based on https://gist.github.com/lsv/4d8044d21819f28f0dde52a3fb8211a0
This commit is contained in:
		| @@ -5,6 +5,7 @@ | ||||
|         "php": "^7.1.3", | ||||
|         "ext-ctype": "*", | ||||
|         "ext-iconv": "*", | ||||
|         "knplabs/knp-menu-bundle": "^2.0", | ||||
|         "sensio/framework-extra-bundle": "^5.1", | ||||
|         "symfony/asset": "*", | ||||
|         "symfony/console": "*", | ||||
|   | ||||
							
								
								
									
										125
									
								
								application/composer.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										125
									
								
								application/composer.lock
									
									
									
										generated
									
									
									
								
							| @@ -4,7 +4,7 @@ | ||||
|         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | ||||
|         "This file is @generated automatically" | ||||
|     ], | ||||
|     "content-hash": "be855819d48e2927e7f5ba7a11b794c5", | ||||
|     "content-hash": "46e513d742140ba387e272208c8a9dc9", | ||||
|     "packages": [ | ||||
|         { | ||||
|             "name": "doctrine/annotations", | ||||
| @@ -1331,6 +1331,129 @@ | ||||
|             ], | ||||
|             "time": "2014-01-12T16:20:24+00:00" | ||||
|         }, | ||||
|         { | ||||
|             "name": "knplabs/knp-menu", | ||||
|             "version": "2.3.0", | ||||
|             "source": { | ||||
|                 "type": "git", | ||||
|                 "url": "https://github.com/KnpLabs/KnpMenu.git", | ||||
|                 "reference": "655630a1db0b72108262d1a844de3b1ba0885be5" | ||||
|             }, | ||||
|             "dist": { | ||||
|                 "type": "zip", | ||||
|                 "url": "https://api.github.com/repos/KnpLabs/KnpMenu/zipball/655630a1db0b72108262d1a844de3b1ba0885be5", | ||||
|                 "reference": "655630a1db0b72108262d1a844de3b1ba0885be5", | ||||
|                 "shasum": "" | ||||
|             }, | ||||
|             "require": { | ||||
|                 "php": ">=5.6.0" | ||||
|             }, | ||||
|             "require-dev": { | ||||
|                 "psr/container": "^1.0", | ||||
|                 "symfony/http-foundation": "~2.4|~3.0|^4.0", | ||||
|                 "symfony/phpunit-bridge": "~3.3|^4.0", | ||||
|                 "symfony/routing": "~2.3|~3.0|^4.0", | ||||
|                 "twig/twig": "~1.16|~2.0" | ||||
|             }, | ||||
|             "suggest": { | ||||
|                 "twig/twig": "for the TwigRenderer and the integration with your templates" | ||||
|             }, | ||||
|             "type": "library", | ||||
|             "extra": { | ||||
|                 "branch-alias": { | ||||
|                     "dev-master": "2.3-dev" | ||||
|                 } | ||||
|             }, | ||||
|             "autoload": { | ||||
|                 "psr-4": { | ||||
|                     "Knp\\Menu\\": "src/Knp/Menu" | ||||
|                 } | ||||
|             }, | ||||
|             "notification-url": "https://packagist.org/downloads/", | ||||
|             "license": [ | ||||
|                 "MIT" | ||||
|             ], | ||||
|             "authors": [ | ||||
|                 { | ||||
|                     "name": "Christophe Coevoet", | ||||
|                     "email": "stof@notk.org" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Symfony Community", | ||||
|                     "homepage": "https://github.com/KnpLabs/KnpMenu/contributors" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "KnpLabs", | ||||
|                     "homepage": "https://knplabs.com" | ||||
|                 } | ||||
|             ], | ||||
|             "description": "An object oriented menu library", | ||||
|             "homepage": "https://knplabs.com", | ||||
|             "keywords": [ | ||||
|                 "menu", | ||||
|                 "tree" | ||||
|             ], | ||||
|             "time": "2017-11-18T20:49:26+00:00" | ||||
|         }, | ||||
|         { | ||||
|             "name": "knplabs/knp-menu-bundle", | ||||
|             "version": "v2.2.1", | ||||
|             "source": { | ||||
|                 "type": "git", | ||||
|                 "url": "https://github.com/KnpLabs/KnpMenuBundle.git", | ||||
|                 "reference": "6bea43eb84fc67c43ab2b43709194efffa8a8ac0" | ||||
|             }, | ||||
|             "dist": { | ||||
|                 "type": "zip", | ||||
|                 "url": "https://api.github.com/repos/KnpLabs/KnpMenuBundle/zipball/6bea43eb84fc67c43ab2b43709194efffa8a8ac0", | ||||
|                 "reference": "6bea43eb84fc67c43ab2b43709194efffa8a8ac0", | ||||
|                 "shasum": "" | ||||
|             }, | ||||
|             "require": { | ||||
|                 "knplabs/knp-menu": "~2.3", | ||||
|                 "php": "^5.6 || ^7", | ||||
|                 "symfony/framework-bundle": "~2.7|~3.0 | ^4.0" | ||||
|             }, | ||||
|             "require-dev": { | ||||
|                 "symfony/expression-language": "~2.7|~3.0 | ^4.0", | ||||
|                 "symfony/phpunit-bridge": "^3.3 | ^4.0", | ||||
|                 "symfony/templating": "~2.7|~3.0 | ^4.0" | ||||
|             }, | ||||
|             "type": "symfony-bundle", | ||||
|             "extra": { | ||||
|                 "branch-alias": { | ||||
|                     "dev-master": "2.2.x-dev" | ||||
|                 } | ||||
|             }, | ||||
|             "autoload": { | ||||
|                 "psr-4": { | ||||
|                     "Knp\\Bundle\\MenuBundle\\": "src" | ||||
|                 } | ||||
|             }, | ||||
|             "notification-url": "https://packagist.org/downloads/", | ||||
|             "license": [ | ||||
|                 "MIT" | ||||
|             ], | ||||
|             "authors": [ | ||||
|                 { | ||||
|                     "name": "Christophe Coevoet", | ||||
|                     "email": "stof@notk.org" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Knplabs", | ||||
|                     "homepage": "http://knplabs.com" | ||||
|                 }, | ||||
|                 { | ||||
|                     "name": "Symfony Community", | ||||
|                     "homepage": "https://github.com/KnpLabs/KnpMenuBundle/contributors" | ||||
|                 } | ||||
|             ], | ||||
|             "description": "This bundle provides an integration of the KnpMenu library", | ||||
|             "keywords": [ | ||||
|                 "menu" | ||||
|             ], | ||||
|             "time": "2017-12-24T16:32:39+00:00" | ||||
|         }, | ||||
|         { | ||||
|             "name": "monolog/monolog", | ||||
|             "version": "1.23.0", | ||||
|   | ||||
| @@ -14,4 +14,5 @@ return [ | ||||
|     Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true], | ||||
|     Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], | ||||
|     Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true], | ||||
|     Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true], | ||||
| ]; | ||||
|   | ||||
| @@ -14,7 +14,13 @@ services: | ||||
|         public: false       # Allows optimizing the container by removing unused services; this also means | ||||
|                             # fetching services directly from the container via $container->get() won't work. | ||||
|                             # The best practice is to be explicit about your dependencies anyway. | ||||
|  | ||||
|     app.menu_builder: | ||||
|         class: App\Menu\Menu | ||||
|     app.menu.usertopbar: | ||||
|         class: Knp\Menu\MenuItem | ||||
|         factory: ['@app.menu_builder', 'userTopbar'] | ||||
|         tags: | ||||
|             - { name: knp_menu.menu, alias: userTopbar } | ||||
|     # makes classes in src/ available to be used as services | ||||
|     # this creates a service per class whose id is the fully-qualified class name | ||||
|     App\: | ||||
|   | ||||
							
								
								
									
										59
									
								
								application/src/Event/Menu/Topbar/UserMenuEvent.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								application/src/Event/Menu/Topbar/UserMenuEvent.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,59 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Event\Menu\Topbar; | ||||
|  | ||||
| use Knp\Menu\FactoryInterface; | ||||
| use Knp\Menu\ItemInterface; | ||||
| use Symfony\Component\EventDispatcher\Event; | ||||
| use Symfony\Component\HttpFoundation\RequestStack; | ||||
|  | ||||
| class UserMenuEvent extends Event | ||||
| { | ||||
|     public const EVENT = 'app.menu.topbar.user'; | ||||
|      | ||||
|     /** | ||||
|      * @var FactoryInterface | ||||
|      */ | ||||
|     private $factory; | ||||
|      | ||||
|     /** | ||||
|      * @var ItemInterface | ||||
|      */ | ||||
|     private $item; | ||||
|      | ||||
|     /** | ||||
|      * @var RequestStack | ||||
|      */ | ||||
|     private $request; | ||||
|      | ||||
|     public function __construct(FactoryInterface $factory, ItemInterface $item, RequestStack $request) | ||||
|     { | ||||
|         $this->factory = $factory; | ||||
|         $this->item = $item; | ||||
|         $this->request = $request; | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * @return FactoryInterface | ||||
|      */ | ||||
|     public function getFactory(): FactoryInterface | ||||
|     { | ||||
|         return $this->factory; | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * @return ItemInterface | ||||
|      */ | ||||
|     public function getItem(): ItemInterface | ||||
|     { | ||||
|         return $this->item; | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * @return RequestStack | ||||
|      */ | ||||
|     public function getRequest(): RequestStack | ||||
|     { | ||||
|         return $this->request; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										42
									
								
								application/src/Menu/Menu.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								application/src/Menu/Menu.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | ||||
| <?php | ||||
| // src/Menu/Menu.php | ||||
|  | ||||
| namespace App\Menu; | ||||
|  | ||||
| use App\Event\Menu\Topbar\UserMenuEvent; | ||||
| use Knp\Menu\FactoryInterface; | ||||
| use Knp\Menu\ItemInterface; | ||||
| use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||||
| use Symfony\Component\HttpFoundation\RequestStack; | ||||
|  | ||||
| class Menu | ||||
| { | ||||
|      | ||||
|     /** | ||||
|      * @var EventDispatcherInterface | ||||
|      */ | ||||
|     private $dispatcher; | ||||
|      | ||||
|     /** | ||||
|      * @var FactoryInterface | ||||
|      */ | ||||
|     private $factory; | ||||
|      | ||||
|     public function __construct(FactoryInterface $factory, EventDispatcherInterface $dispatcher) | ||||
|     { | ||||
|         $this->dispatcher = $dispatcher; | ||||
|         $this->factory = $factory; | ||||
|     } | ||||
|      | ||||
|     public function userTopbar(RequestStack $request): ItemInterface | ||||
|     { | ||||
|         $menu = $this->factory->createItem('root'); | ||||
|          | ||||
|         $this->dispatcher->dispatch( | ||||
|             UserMenuEvent::EVENT, | ||||
|             new UserMenuEvent($this->factory, $menu, $request) | ||||
|             ); | ||||
|          | ||||
|         return $menu; | ||||
|     }    | ||||
| } | ||||
							
								
								
									
										54
									
								
								application/src/Subscriber/UserMenuSubscriber.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								application/src/Subscriber/UserMenuSubscriber.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| <?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; | ||||
| 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) | ||||
|     { | ||||
|         $menu = $event->getItem(); | ||||
|         /** @var User $user */ | ||||
|         $user = $this->tokenStorage->getToken()->getUser(); | ||||
|   | ||||
|         $dropdown = $menu->addChild( | ||||
|             $this->translator->trans('Hello %username%', ['%username%' => 'Noname'], 'usermenu'), | ||||
|             ['dropdown' => true] | ||||
|             ); | ||||
|          | ||||
|         $dropdown->addChild( | ||||
|             $this->translator->trans('Login', [], 'usermenu'), | ||||
|             ['route' => 'user_login'] | ||||
|             ); | ||||
|     } | ||||
|      | ||||
|     public static function getSubscribedEvents(): array | ||||
|     { | ||||
|         return [ | ||||
|             UserMenuEvent::EVENT => 'onUserMenuConfigure', | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
| @@ -83,6 +83,12 @@ | ||||
|     "jdorn/sql-formatter": { | ||||
|         "version": "v1.2.17" | ||||
|     }, | ||||
|     "knplabs/knp-menu": { | ||||
|         "version": "2.3.0" | ||||
|     }, | ||||
|     "knplabs/knp-menu-bundle": { | ||||
|         "version": "v2.2.1" | ||||
|     }, | ||||
|     "monolog/monolog": { | ||||
|         "version": "1.23.0" | ||||
|     }, | ||||
|   | ||||
| @@ -1,9 +1,10 @@ | ||||
| {% extends "base.html.twig" %} | ||||
| {% block body %} | ||||
| {% include 'frames/structure/navbar.html.twig' with menu_items %} | ||||
| {% include 'topbar.html.twig' %} | ||||
| <br /> | ||||
| <div class="container"> | ||||
| 	{% block content %} | ||||
| 	{% endblock %} | ||||
| </div> | ||||
| {% endblock %} | ||||
| {% endblock %} | ||||
|   | ||||
							
								
								
									
										3
									
								
								application/templates/topbar.html.twig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								application/templates/topbar.html.twig
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| {# templates/topbar.htm.twig #} | ||||
|  | ||||
| {{ knp_menu_render('userTopbar') }} | ||||
		Reference in New Issue
	
	Block a user