diff --git a/application/composer.json b/application/composer.json index 9e6e467..803b2ea 100644 --- a/application/composer.json +++ b/application/composer.json @@ -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": "*", diff --git a/application/composer.lock b/application/composer.lock index 9c2180d..7026bef 100644 --- a/application/composer.lock +++ b/application/composer.lock @@ -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", diff --git a/application/config/bundles.php b/application/config/bundles.php index 3b121fd..6e2c04e 100644 --- a/application/config/bundles.php +++ b/application/config/bundles.php @@ -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], ]; diff --git a/application/config/services.yaml b/application/config/services.yaml index 776e6ce..b7d3d2c 100644 --- a/application/config/services.yaml +++ b/application/config/services.yaml @@ -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\: diff --git a/application/src/Event/Menu/Topbar/UserMenuEvent.php b/application/src/Event/Menu/Topbar/UserMenuEvent.php new file mode 100644 index 0000000..f71a6c8 --- /dev/null +++ b/application/src/Event/Menu/Topbar/UserMenuEvent.php @@ -0,0 +1,59 @@ +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; + } +} \ No newline at end of file diff --git a/application/src/Menu/Menu.php b/application/src/Menu/Menu.php new file mode 100644 index 0000000..aa15e69 --- /dev/null +++ b/application/src/Menu/Menu.php @@ -0,0 +1,42 @@ +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; + } +} \ No newline at end of file diff --git a/application/src/Subscriber/UserMenuSubscriber.php b/application/src/Subscriber/UserMenuSubscriber.php new file mode 100644 index 0000000..a27048e --- /dev/null +++ b/application/src/Subscriber/UserMenuSubscriber.php @@ -0,0 +1,54 @@ +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', + ]; + } +} \ No newline at end of file diff --git a/application/symfony.lock b/application/symfony.lock index 4ddc893..7fd2dbe 100644 --- a/application/symfony.lock +++ b/application/symfony.lock @@ -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" }, diff --git a/application/templates/frames/default.html.twig b/application/templates/frames/default.html.twig index 8f7d51c..ccde14b 100644 --- a/application/templates/frames/default.html.twig +++ b/application/templates/frames/default.html.twig @@ -1,9 +1,10 @@ {% extends "base.html.twig" %} {% block body %} {% include 'frames/structure/navbar.html.twig' with menu_items %} +{% include 'topbar.html.twig' %}
{% block content %} {% endblock %}
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/application/templates/topbar.html.twig b/application/templates/topbar.html.twig new file mode 100644 index 0000000..2a82929 --- /dev/null +++ b/application/templates/topbar.html.twig @@ -0,0 +1,3 @@ +{# templates/topbar.htm.twig #} + +{{ knp_menu_render('userTopbar') }} \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..2c63c08 --- /dev/null +++ b/composer.json @@ -0,0 +1,2 @@ +{ +}