From 47a384d80289a787253cfab7fc2404ffd2919e4b Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 22 Jul 2026 16:35:54 +0200 Subject: [PATCH] fix(navigation): Missing logout entry When using some other user backends like the one from global scale, the user session is not yet available in the boot process which makes IUserSession::isLoggedIn fail. Signed-off-by: Carl Schwan --- core/AppInfo/Application.php | 34 ++++++++++++++++--------------- lib/private/NavigationManager.php | 7 +++++-- lib/public/INavigationManager.php | 6 +++--- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/core/AppInfo/Application.php b/core/AppInfo/Application.php index fd396fa7f08dc..9402dde15c254 100644 --- a/core/AppInfo/Application.php +++ b/core/AppInfo/Application.php @@ -170,21 +170,23 @@ public function registerNavigationEntries( IURLGenerator $urlGenerator, IFactory $factory, ): void { - if (!$userSession->isLoggedIn()) { - return; - } - - $l = $factory->get('core'); - - // Register the logout button in the user settings - $logoutUrl = $urlGenerator->getLogoutUrl(); - $navigationManager->add([ - 'type' => 'settings', - 'id' => 'logout', - 'order' => 99999, - 'href' => $logoutUrl, - 'name' => $l->t('Log out'), - 'icon' => $urlGenerator->imagePath('core', 'actions/logout.svg'), - ]); + $navigationManager->add(function () use ($userSession, $factory, $urlGenerator): ?array { + if (!$userSession->isLoggedIn()) { + return null; + } + + $l = $factory->get('core'); + + // Register the logout button in the user settings + $logoutUrl = $urlGenerator->getLogoutUrl(); + return [ + 'type' => 'settings', + 'id' => 'logout', + 'order' => 99999, + 'href' => $logoutUrl, + 'name' => $l->t('Log out'), + 'icon' => $urlGenerator->imagePath('core', 'actions/logout.svg'), + ]; + }); } } diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index 468e2617d67f0..7c6c95724c3b6 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -30,7 +30,7 @@ class NavigationManager implements INavigationManager { /** @var array */ protected array $entries = []; - /** @var list */ + /** @var list */ protected array $closureEntries = []; protected ?string $activeEntry = null; protected array $unreadCounters = []; @@ -208,7 +208,10 @@ private function init(): void { private function resolveAppNavigationEntries(): void { // Resolve app navigation closures while ($c = array_pop($this->closureEntries)) { - $this->add($c()); + $entry = $c(); + if ($entry !== null) { + $this->add($entry); + } } // Resolve dynamically added navigation entries via event listeners diff --git a/lib/public/INavigationManager.php b/lib/public/INavigationManager.php index 005c35282f416..1c362cc8d15e4 100644 --- a/lib/public/INavigationManager.php +++ b/lib/public/INavigationManager.php @@ -63,9 +63,9 @@ interface INavigationManager { /** * Creates a new navigation entry * - * @param NavigationEntry|callable():NavigationEntry $entry If a menu entry (type = 'link') is added, you shall also set app to the app that - * added the entry. The use of a closure is preferred, because it will avoid loading - * the routing of your app, unless required. + * @param NavigationEntry|callable():?NavigationEntry $entry If a menu entry (type = 'link') is added, you shall also set app to the app that + * added the entry. The use of a closure is preferred, because it will avoid loading + * the routing of your app, unless required. * @return void * @since 6.0.0 */