diff --git a/application/src/Controller/DefaultController.php b/application/src/Controller/DefaultController.php index bdf8718..6ccb204 100644 --- a/application/src/Controller/DefaultController.php +++ b/application/src/Controller/DefaultController.php @@ -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"); } } diff --git a/application/src/Controller/UserController.php b/application/src/Controller/UserController.php index b17cc80..aa09860 100644 --- a/application/src/Controller/UserController.php +++ b/application/src/Controller/UserController.php @@ -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"); } - } \ No newline at end of file diff --git a/application/src/Menu/Menu.php b/application/src/Menu/Menu.php index aa15e69..008ba99 100644 --- a/application/src/Menu/Menu.php +++ b/application/src/Menu/Menu.php @@ -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, diff --git a/application/src/Subscriber/UserMenuSubscriber.php b/application/src/Subscriber/UserMenuSubscriber.php index a27048e..abbcb92 100644 --- a/application/src/Subscriber/UserMenuSubscriber.php +++ b/application/src/Subscriber/UserMenuSubscriber.php @@ -1,9 +1,5 @@ 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' ]; } -} \ No newline at end of file +} diff --git a/application/templates/frames/default.html.twig b/application/templates/frames/default.html.twig index ccde14b..60f05a8 100644 --- a/application/templates/frames/default.html.twig +++ b/application/templates/frames/default.html.twig @@ -1,7 +1,6 @@ {% extends "base.html.twig" %} {% block body %} -{% include 'frames/structure/navbar.html.twig' with menu_items %} -{% include 'topbar.html.twig' %} +{% include 'frames/structure/navbar.html.twig'%}
{% block content %} diff --git a/application/templates/frames/structure/knp_menu.html.twig b/application/templates/frames/structure/knp_menu.html.twig new file mode 100644 index 0000000..43eff38 --- /dev/null +++ b/application/templates/frames/structure/knp_menu.html.twig @@ -0,0 +1,200 @@ +{# @see https://gist.github.com/lsv/24a9e9d7d961d22226f8e220d2c4a7d0 #} +{% extends 'knp_menu.html.twig' %} + +{% macro setCssClassAttribute(item, type, add) %} + {% set getter = 'get' ~ type %} + {% set setter = 'set' ~ type %} + {% set value = attribute(item, getter, ['class']) %} + {% if value is iterable %} + {% set value = value|join(' ') %} + {% endif %} + {% do attribute(item, setter, ['class', value ~ ' ' ~ add]) %} +{% endmacro %} + +{% block item %} + {% import "knp_menu.html.twig" as macros %} + {# + As multiple level is not currently supported by bootstrap 4 + This requires you to install + https://github.com/bootstrapthemesco/bootstrap-4-multi-dropdown-navbar + And set the the use_multilevel = true + #} + {% set use_multilevel = false %} + + {% if item.displayed %} + {%- set attributes = item.attributes %} + {%- set is_dropdown = attributes.dropdown|default(false) %} + {%- set divider_prepend = attributes.divider_prepend|default(false) %} + {%- set divider_append = attributes.divider_append|default(false) %} + + {# unset bootstrap specific attributes #} + {%- set attributes = attributes|merge({'dropdown': null, 'divider_prepend': null, 'divider_append': null }) %} + + {%- if divider_prepend %} + {{ block('dividerElement') }} + {%- endif %} + + {# building the class of the item #} + {%- set classes = item.attribute('class') is not empty ? [item.attribute('class'), 'nav-item'] : ['nav-item'] %} + {%- if matcher.isCurrent(item) %} + {%- set classes = classes|merge([options.currentClass]) %} + {%- elseif matcher.isAncestor(item, options.depth) %} + {%- set classes = classes|merge([options.ancestorClass]) %} + {%- endif %} + {%- if item.actsLikeFirst %} + {%- set classes = classes|merge([options.firstClass]) %} + {%- endif %} + {%- if item.actsLikeLast %} + {%- set classes = classes|merge([options.lastClass]) %} + {%- endif %} + + {# building the class of the children #} + {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %} + {%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %} + + {# adding classes for dropdown #} + {%- if is_dropdown %} + {%- set classes = classes|merge(['dropdown']) %} + {%- set childrenClasses = childrenClasses|merge(['dropdown-menu']) %} + {%- endif %} + + {# putting classes together #} + {%- if classes is not empty %} + {%- set attributes = attributes|merge({'class': classes|join(' ')}) %} + {%- endif %} + {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %} + + + {# displaying the item #} + {%- if is_dropdown %} + {{ block('dropdownElement') }} + {%- elseif item.uri is not empty and (not item.current or options.currentAsLink) %} + {{ block('linkElement') }} + {%- else %} + {{ block('spanElement') }} + {%- endif %} + {%- if divider_append %} + {{ block('dividerElement') }} + {%- endif %} + {% if item.hasChildren and options.depth is not same as(0) and item.displayChildren %} + {{ block('dropdownlinks') }} + {% endif %} + + {% endif %} +{% endblock %} + +{% block dropdownlinks %} + {% if use_multilevel %} + + {% endif %} +{% endblock %} + +{% block renderDropdownlink %} + {% import _self as ownmacro %} + {%- set divider_prepend = item.attributes.divider_prepend|default(false) %} + {%- set divider_append = item.attributes.divider_append|default(false) %} + {%- set attributes = item.attributes|merge({'dropdown': null, 'divider_prepend': null, 'divider_append': null }) %} + + {% if use_multilevel %} +
  • + {% endif %} + + {%- if divider_prepend %} + {{ block('dividerElementDropdown') }} + {%- endif %} + + {%- if item.uri is not empty and (not item.current or options.currentAsLink) %} + {{ ownmacro.setCssClassAttribute(item, 'LinkAttribute', 'dropdown-item') }} + {{ block('linkElement') }} + {%- else %} + {{ block('spanElementDropdown') }} + {%- endif %} + + {%- if divider_append %} + {{ block('dividerElementDropdown') }} + {%- endif %} + + {% if use_multilevel %} +
  • + {% endif %} +{% endblock %} + +{% block spanElementDropdown %} + {% import "knp_menu.html.twig" as macros %} + {% import _self as ownmacro %} + {{ ownmacro.setCssClassAttribute(item, 'LabelAttribute', 'dropdown-header') }} +
    + {% if item.attribute('icon') is not empty %} + + {% endif %} + {{ block('label') }} +
    +{% endblock %} + +{% block dividerElementDropdown %} + +{% endblock %} + +{% block dividerElement %} + {% if item.level == 1 %} +
  • + {% else %} +
  • + {% endif %} +{% endblock %} + +{% block linkElement %} + {% import "knp_menu.html.twig" as macros %} + {% import _self as ownmacro %} + {{ ownmacro.setCssClassAttribute(item, 'LinkAttribute', 'nav-link') }} + + {% if item.attribute('icon') is not empty %} + + {% endif %} + {{ block('label') }} + +{% endblock %} + +{% block spanElement %} + {% import "knp_menu.html.twig" as macros %} + {% import _self as ownmacro %} + {{ ownmacro.setCssClassAttribute(item, 'LabelAttribute', 'navbar-text') }} + + {% if item.attribute('icon') is not empty %} + + {% endif %} + {{ block('label') }} + +{% endblock %} + +{% block dropdownElement %} + {% import "knp_menu.html.twig" as macros %} + {%- set classes = item.linkAttribute('class') is not empty ? [item.linkAttribute('class')] : [] %} + {%- set classes = classes|merge(['dropdown-toggle', 'nav-link']) %} + {%- set attributes = item.linkAttributes %} + {%- set attributes = attributes|merge({'class': classes|join(' ')}) %} + {%- set attributes = attributes|merge({'data-toggle': 'dropdown'}) %} + + {% if item.attribute('icon') is not empty %} + + {% endif %} + {{ block('label') }} + + +{% endblock %} + +{% block label %}{{ item.label|trans }}{% endblock %} diff --git a/application/templates/frames/structure/navbar.html.twig b/application/templates/frames/structure/navbar.html.twig index 24ffad2..02009d2 100644 --- a/application/templates/frames/structure/navbar.html.twig +++ b/application/templates/frames/structure/navbar.html.twig @@ -7,29 +7,6 @@ diff --git a/application/templates/topbar.html.twig b/application/templates/topbar.html.twig deleted file mode 100644 index 2a82929..0000000 --- a/application/templates/topbar.html.twig +++ /dev/null @@ -1,3 +0,0 @@ -{# templates/topbar.htm.twig #} - -{{ knp_menu_render('userTopbar') }} \ No newline at end of file