Skip to content

Commit 02801e1

Browse files
committed
fix(navigation): Allow apps to hide registered navigation closure entries
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent ed02732 commit 02801e1

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎lib/private/NavigationManager.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class NavigationManager implements INavigationManager {
5757
protected ?string $activeEntry = null;
5858
/** @var array<string, NavigationEntryOutput> */
5959
protected array $entries = [];
60-
/** @var list<callable(): NavigationEntry> */
60+
/** @var list<callable(): ?NavigationEntry> */
6161
protected array $closureEntries = [];
6262
/** User defined app order (cached for the `add` function) */
6363
protected ?array $customAppOrder = null;
@@ -357,7 +357,12 @@ private function resolveAppNavigationEntries(): void {
357357
// as apps might add new navigation entries via closures at any time
358358
while ($c = array_pop($this->closureEntries)) {
359359
try {
360-
$this->add($c());
360+
$entry = $c();
361+
if ($entry === null) {
362+
$this->logger->debug('Closure of navigation entry returned null, skipping');
363+
continue;
364+
}
365+
$this->add($entry);
361366
} catch (\Throwable $e) {
362367
$this->logger->error('Failed to add navigation entry from closure', ['exception' => $e]);
363368
}

‎lib/public/INavigationManager.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ interface INavigationManager {
8080
/**
8181
* Creates a new navigation entry
8282
*
83-
* @param NavigationEntry|callable():NavigationEntry $entry If a menu entry (type = 'link') is added, you shall also set app to the app that
83+
* @param NavigationEntry|callable():?NavigationEntry $entry If a menu entry (type = 'link') is added, you shall also set app to the app that
8484
* added the entry. The use of a closure is preferred, because it will avoid loading
8585
* the routing of your app, unless required.
8686
* @return void

0 commit comments

Comments
 (0)