feat: add a Mein Account group to the main menu and lock the page while the drawer is open

This commit is contained in:
fromme committed 2026-11-13 15:04:29 +01:00
1 parent 4530d2434b
commit 8a02b28d00
6 files changed
+164 -24

No files matched your search

+21 -12
View File
@@ -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'] : [],
]);
}
}
+22 -2
View File
@@ -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
{