Fix menu item sorting by using sortBy() instead of sort() (#18220)

Changed Collection::sort() to Collection::sortBy() in getUserMenuItems()
and getTenantMenuItems() methods. The sort() method expects a comparison
callback but was being called with a single-parameter callback that returns
a value, resulting in unpredictable sorting order. sortBy() correctly sorts
by the returned value.

This ensures menu items are consistently ordered by their sort value.
This commit is contained in:
Mark Chaney
2025-10-15 08:20:18 +01:00
committed by GitHub
parent 38b5dee412
commit f3778982ea
2 changed files with 2 additions and 2 deletions
@@ -383,7 +383,7 @@ trait HasTenancy
fn (Collection $items): Collection => $items->put('register', $this->getTenantRegistrationMenuItem()),
)
->filter(fn (Action $item): bool => $item->isVisible())
->sort(fn (Action $item): int => $item->getSort())
->sortBy(fn (Action $item): int => $item->getSort())
->all();
}
@@ -127,7 +127,7 @@ trait HasUserMenu
fn (Collection $items): Collection => $items->put('logout', $this->getUserLogoutMenuItem()),
)
->filter(fn (Action $item): bool => $item->isVisible())
->sort(fn (Action $item): int => $item->getSort())
->sortBy(fn (Action $item): int => $item->getSort())
->all();
}
}