From 8a02b28d00e7255dda9bd4caa0a810ba6aec117e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Fri, 13 Nov 2026 15:04:29 +0100 Subject: [PATCH] feat: add a Mein Account group to the main menu and lock the page while the drawer is open --- assets/styles/ep-design.css | 8 ++ src/Menu/AbstractMenuBuilder.php | 33 ++++--- src/Menu/MenuBuilder.php | 24 ++++- templates/_partials/_user_menu.html.twig | 10 +-- templates/layout.html.twig | 7 +- tests/Menu/MainMenuAccountGroupTest.php | 106 +++++++++++++++++++++++ 6 files changed, 164 insertions(+), 24 deletions(-) create mode 100644 tests/Menu/MainMenuAccountGroupTest.php diff --git a/assets/styles/ep-design.css b/assets/styles/ep-design.css index e68e3fc..8d03794 100644 --- a/assets/styles/ep-design.css +++ b/assets/styles/ep-design.css @@ -252,6 +252,14 @@ @apply m-0 h-dvh max-h-none w-80 max-w-[calc(100vw-4rem)] bg-page p-0; } + /* + * a modal dialog doesn't stop the page behind it from scrolling: on touch screens the page took the + * gesture first, and a long navigation in the drawer only scrolled once the page was at its end + */ + html:has(dialog.drawer:modal) { + @apply overflow-hidden; + } + /* lists in a card: the outer cells line up with the card's padding */ .data-table { @apply w-full; diff --git a/src/Menu/AbstractMenuBuilder.php b/src/Menu/AbstractMenuBuilder.php index 5329589..a9838d1 100644 --- a/src/Menu/AbstractMenuBuilder.php +++ b/src/Menu/AbstractMenuBuilder.php @@ -150,20 +150,33 @@ abstract class AbstractMenuBuilder ]; /** - * Adds the links to the other areas the user has, then logout, or the way back to the - * own user while impersonating someone. + * Adds the own profile, the links to the other areas the user has, then logout, or the way + * back to the own user while impersonating someone. + * + * Without icons for the sidebar, where they are sub-items and sub-items carry none. */ - protected function addAccountItems(ItemInterface $menu): void + protected function addAccountItems(ItemInterface $menu, bool $withIcons = true, bool $withProfile = true): void { $currentArea = $this->resolveArea(); + $user = $this->security->getUser(); + $profileRoute = match (true) { + $user instanceof User && null !== $user->getTeamer() => 'app_teamer_profile_index', + $this->security->isGranted('ROLE_ADMINISTRATIVE') => 'app_administrative_profile_index', + default => null, + }; + + if ($withProfile && null !== $profileRoute) { + $menu->addChild('Mein Profil', [ + 'route' => $profileRoute, + 'extras' => $withIcons ? ['icon' => 'user'] : [], + ]); + } foreach (self::AREA_LINKS as $role => [$label, $route]) { if ($role !== $currentArea && $this->security->isGranted($role)) { $menu->addChild($label, [ 'route' => $route, - 'extras' => [ - 'icon' => 'arrow-right', - ], + 'extras' => $withIcons ? ['icon' => 'arrow-right'] : [], ]); } } @@ -176,16 +189,12 @@ abstract class AbstractMenuBuilder $menu->addChild('zum eigenen Benutzer', [ 'route' => $originalUser->getDefaultRoute(), 'routeParameters' => ['_switch_user' => '_exit'], - 'extras' => [ - 'icon' => 'logout', - ], + 'extras' => $withIcons ? ['icon' => 'logout'] : [], ]); } else { $menu->addChild('Logout', [ 'route' => 'app_security_logout', - 'extras' => [ - 'icon' => 'logout', - ], + 'extras' => $withIcons ? ['icon' => 'logout'] : [], ]); } } diff --git a/src/Menu/MenuBuilder.php b/src/Menu/MenuBuilder.php index f6a7f32..fddb141 100644 --- a/src/Menu/MenuBuilder.php +++ b/src/Menu/MenuBuilder.php @@ -2,6 +2,7 @@ namespace App\Menu; +use App\Entity\User; use Knp\Menu\FactoryInterface; use Knp\Menu\ItemInterface; use Symfony\Bundle\SecurityBundle\Security; @@ -31,17 +32,36 @@ class MenuBuilder extends AbstractMenuBuilder public function createMainMenu(array $options): ItemInterface { - return match ($this->resolveArea()) { + $area = $this->resolveArea(); + $menu = match ($area) { 'ROLE_TEAM_ADMIN' => $this->adminMenuBuilder->createMainMenu($options), 'ROLE_MANAGER' => $this->managerMenuBuilder->createMainMenu($options), 'ROLE_HOUSE_MANAGER' => $this->houseManagerMenuBuilder->createMainMenu($options), 'ROLE_TEAMER' => $this->teamerMenuBuilder->createMainMenu($options), default => $this->createRootElement(), }; + + $user = $this->security->getUser(); + + if ($user instanceof User) { + $this->addDivider($menu); + + // A group without uri, so the sidebar renders it collapsible; the teamer menu has its own "Mein Profil". + $account = $menu->addChild('account', [ + 'label' => 'Mein Account', + 'extras' => [ + 'icon' => 'user', + ], + ]); + + $this->addAccountItems($account, withIcons: false, withProfile: 'ROLE_TEAMER' !== $area); + } + + return $menu; } /** - * The account menu behind the user's picture in the header: the other areas and logout. + * The account menu behind the user's picture in the header: own profile, the other areas and logout. */ public function createUserMenu(array $options): ItemInterface { diff --git a/templates/_partials/_user_menu.html.twig b/templates/_partials/_user_menu.html.twig index d9ad0f7..01bc561 100644 --- a/templates/_partials/_user_menu.html.twig +++ b/templates/_partials/_user_menu.html.twig @@ -1,6 +1,7 @@ {# - The account menu behind the user's picture: own profile, the other areas (MenuBuilder::createUserMenu) - and logout. Opens on click, closes on a click elsewhere and on Escape. + The account menu behind the user's picture: own profile, the other areas and logout + (MenuBuilder::createUserMenu). Opens on click, closes on a click elsewhere and on Escape. Only from lg + up; below that the same items are reached through the main menu in the drawer. #} {% set user_menu = knp_menu_get('default_user') %}