aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/NavigationManager.php
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2023-10-10 14:24:34 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2023-10-19 22:04:20 +0200
commit363d9ebb130862d5fc5617e94b1c369caf02553f (patch)
tree075425b702790fdd13c58fb396d72c1e6a22f544 /lib/private/NavigationManager.php
parent08cff0777aac169dd9c758b73faa0060004fc7a0 (diff)
downloadnextcloud-server-363d9ebb130862d5fc5617e94b1c369caf02553f.tar.gz
nextcloud-server-363d9ebb130862d5fc5617e94b1c369caf02553f.zip
feat(NavigationManager): Always sort the default app first
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'lib/private/NavigationManager.php')
-rw-r--r--lib/private/NavigationManager.php46
1 files changed, 40 insertions, 6 deletions
diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php
index a651cde379d..d34ba5fed98 100644
--- a/lib/private/NavigationManager.php
+++ b/lib/private/NavigationManager.php
@@ -123,26 +123,44 @@ class NavigationManager implements INavigationManager {
});
}
- return $this->proceedNavigation($result);
+ return $this->proceedNavigation($result, $type);
}
/**
- * Sort navigation entries by order, name and set active flag
+ * Sort navigation entries default app is always sorted first, then by order, name and set active flag
*
* @param array $list
* @return array
*/
- private function proceedNavigation(array $list): array {
+ private function proceedNavigation(array $list, string $type): array {
uasort($list, function ($a, $b) {
- if (isset($a['order']) && isset($b['order'])) {
+ if (($a['default'] ?? false) xor ($b['default'] ?? false)) {
+ // Always sort the default app first
+ return ($a['default'] ?? false) ? -1 : 1;
+ } elseif (isset($a['order']) && isset($b['order'])) {
+ // Sort by order
return ($a['order'] < $b['order']) ? -1 : 1;
} elseif (isset($a['order']) || isset($b['order'])) {
+ // Sort the one that has an order property first
return isset($a['order']) ? -1 : 1;
} else {
+ // Sort by name otherwise
return ($a['name'] < $b['name']) ? -1 : 1;
}
});
+ if ($type === 'all' || $type === 'link') {
+ // There might be the case that no default app was set, in this case the first app is the default app.
+ // Otherwise the default app is already the ordered first, so setting the default prop will make no difference.
+ foreach ($list as $index => &$navEntry) {
+ if ($navEntry['type'] === 'link') {
+ $navEntry['default'] = true;
+ break;
+ }
+ }
+ unset($navEntry);
+ }
+
$activeApp = $this->getActiveEntry();
if ($activeApp !== null) {
foreach ($list as $index => &$navEntry) {
@@ -293,6 +311,8 @@ class NavigationManager implements INavigationManager {
$customOrders = [];
}
+ // The default app of the current user without fallbacks
+ $defaultApp = $this->appManager->getDefaultAppForUser($this->userSession->getUser(), false);
foreach ($apps as $app) {
if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
@@ -335,14 +355,28 @@ class NavigationManager implements INavigationManager {
$icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
}
- $this->add([
+ $this->add(array_merge([
+ // Navigation id
'id' => $id,
+ // Order where this entry should be shown
'order' => $order,
+ // Target of the navigation entry
'href' => $route,
+ // The icon used for the naviation entry
'icon' => $icon,
+ // Type of the navigation entry ('link' vs 'settings')
'type' => $type,
+ // Localized name of the navigation entry
'name' => $l->t($nav['name']),
- ]);
+ ], $type === 'link' ? [
+ // This is the default app that will always be shown first
+ 'default' => $defaultApp === $id,
+ // App that registered this navigation entry (not necessarly the same as the id)
+ 'app' => $app,
+ // The key used to identify this entry in the navigations entries
+ 'key' => $key,
+ ] : []
+ ));
}
}
}