summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/NavigationManager.php51
-rw-r--r--lib/private/TemplateLayout.php4
-rw-r--r--lib/private/legacy/app.php33
-rw-r--r--lib/public/INavigationManager.php9
6 files changed, 60 insertions, 39 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 3eb532be0c6..06879c5179a 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -521,6 +521,7 @@ return array(
'OC\\Core\\Controller\\JsController' => $baseDir . '/core/Controller/JsController.php',
'OC\\Core\\Controller\\LoginController' => $baseDir . '/core/Controller/LoginController.php',
'OC\\Core\\Controller\\LostController' => $baseDir . '/core/Controller/LostController.php',
+ 'OC\\Core\\Controller\\NavigationController' => $baseDir . '/core/Controller/NavigationController.php',
'OC\\Core\\Controller\\OCJSController' => $baseDir . '/core/Controller/OCJSController.php',
'OC\\Core\\Controller\\OCSController' => $baseDir . '/core/Controller/OCSController.php',
'OC\\Core\\Controller\\PreviewController' => $baseDir . '/core/Controller/PreviewController.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 2483b5689b3..118094c30ef 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -551,6 +551,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Core\\Controller\\JsController' => __DIR__ . '/../../..' . '/core/Controller/JsController.php',
'OC\\Core\\Controller\\LoginController' => __DIR__ . '/../../..' . '/core/Controller/LoginController.php',
'OC\\Core\\Controller\\LostController' => __DIR__ . '/../../..' . '/core/Controller/LostController.php',
+ 'OC\\Core\\Controller\\NavigationController' => __DIR__ . '/../../..' . '/core/Controller/NavigationController.php',
'OC\\Core\\Controller\\OCJSController' => __DIR__ . '/../../..' . '/core/Controller/OCJSController.php',
'OC\\Core\\Controller\\OCSController' => __DIR__ . '/../../..' . '/core/Controller/OCSController.php',
'OC\\Core\\Controller\\PreviewController' => __DIR__ . '/../../..' . '/core/Controller/PreviewController.php',
diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php
index 31d147a3b80..279c899c5fa 100644
--- a/lib/private/NavigationManager.php
+++ b/lib/private/NavigationManager.php
@@ -104,26 +104,61 @@ class NavigationManager implements INavigationManager {
}
/**
- * returns all the added Menu entries
- * @param string $type
- * @return array an array of the added entries
+ * Get a list of navigation entries
+ *
+ * @param string $type type of the navigation entries
+ * @return array
*/
- public function getAll($type = 'link') {
+ public function getAll(string $type = 'link'): array {
$this->init();
foreach ($this->closureEntries as $c) {
$this->add($c());
}
$this->closureEntries = array();
- if ($type === 'all') {
- return $this->entries;
+ $result = $this->entries;
+ if ($type !== 'all') {
+ $result = array_filter($this->entries, function($entry) use ($type) {
+ return $entry['type'] === $type;
+ });
}
- return array_filter($this->entries, function($entry) use ($type) {
- return $entry['type'] === $type;
+ return $this->proceedNavigation($result);
+ }
+
+ /**
+ * Sort navigation entries by order, name and set active flag
+ *
+ * @param array $list
+ * @return array
+ */
+ private function proceedNavigation(array $list): array {
+ usort($list, function($a, $b) {
+ if (isset($a['order']) && isset($b['order'])) {
+ return ($a['order'] < $b['order']) ? -1 : 1;
+ } else if (isset($a['order']) || isset($b['order'])) {
+ return isset($a['order']) ? -1 : 1;
+ } else {
+ return ($a['name'] < $b['name']) ? -1 : 1;
+ }
});
+
+ $activeApp = $this->getActiveEntry();
+ if ($activeApp !== null) {
+ foreach ($list as $index => &$navEntry) {
+ if ($navEntry['id'] == $activeApp) {
+ $navEntry['active'] = true;
+ } else {
+ $navEntry['active'] = false;
+ }
+ }
+ unset($navEntry);
+ }
+
+ return $list;
}
+
/**
* removes all the entries
*/
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index d37a8bbabbe..8cc235bf818 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -80,9 +80,9 @@ class TemplateLayout extends \OC_Template {
// Add navigation entry
$this->assign( 'application', '');
$this->assign( 'appid', $appId );
- $navigation = \OC_App::getNavigation();
+ $navigation = \OC::$server->getNavigationManager()->getAll();
$this->assign( 'navigation', $navigation);
- $settingsNavigation = \OC_App::getSettingsNavigation();
+ $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings');
$this->assign( 'settingsnavigation', $settingsNavigation);
foreach($navigation as $entry) {
if ($entry['active']) {
diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php
index 9384582bac3..f97b74ed24f 100644
--- a/lib/private/legacy/app.php
+++ b/lib/private/legacy/app.php
@@ -445,31 +445,6 @@ class OC_App {
$appManager->disableApp($app);
}
- // This is private as well. It simply works, so don't ask for more details
- private static function proceedNavigation($list) {
- usort($list, function($a, $b) {
- if (isset($a['order']) && isset($b['order'])) {
- return ($a['order'] < $b['order']) ? -1 : 1;
- } else if (isset($a['order']) || isset($b['order'])) {
- return isset($a['order']) ? -1 : 1;
- } else {
- return ($a['name'] < $b['name']) ? -1 : 1;
- }
- });
-
- $activeApp = OC::$server->getNavigationManager()->getActiveEntry();
- foreach ($list as $index => &$navEntry) {
- if ($navEntry['id'] == $activeApp) {
- $navEntry['active'] = true;
- } else {
- $navEntry['active'] = false;
- }
- }
- unset($navEntry);
-
- return $list;
- }
-
/**
* Get the path where to install apps
*
@@ -613,6 +588,7 @@ class OC_App {
* Returns the navigation
*
* @return array
+ * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll()
*
* This function returns an array containing all entries added. The
* entries are sorted by the key 'order' ascending. Additional to the keys
@@ -620,21 +596,20 @@ class OC_App {
* - active: boolean, signals if the user is on this navigation entry
*/
public static function getNavigation() {
- $entries = OC::$server->getNavigationManager()->getAll();
- return self::proceedNavigation($entries);
+ return OC::$server->getNavigationManager()->getAll();
}
/**
* Returns the Settings Navigation
*
* @return string[]
+ * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll('settings')
*
* This function returns an array containing all settings pages added. The
* entries are sorted by the key 'order' ascending.
*/
public static function getSettingsNavigation() {
- $entries = OC::$server->getNavigationManager()->getAll('settings');
- return self::proceedNavigation($entries);
+ return OC::$server->getNavigationManager()->getAll('settings');
}
/**
diff --git a/lib/public/INavigationManager.php b/lib/public/INavigationManager.php
index 216f8a897d8..77b881b8b15 100644
--- a/lib/public/INavigationManager.php
+++ b/lib/public/INavigationManager.php
@@ -57,4 +57,13 @@ interface INavigationManager {
* @since 6.0.0
*/
public function setActiveEntry($appId);
+
+ /**
+ * Get a list of navigation entries
+ *
+ * @param string $type type of the navigation entries
+ * @return array
+ * @since 14.0.0
+ */
+ public function getAll(string $type = 'link'): array;
}