summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-02-15 16:55:12 +0100
committerGitHub <noreply@github.com>2018-02-15 16:55:12 +0100
commit14bc9b171427c1512226d5ea402021d8b44ac690 (patch)
tree1a4b9c64f711becf429f90da69d3d46279c55435 /lib/private
parent8a505e8767fe7af62a4e9e8d95ef2e336b05bf61 (diff)
parente694b30a4f1e1cce6cbca0fcbbfeceee8a16c8f6 (diff)
downloadnextcloud-server-14bc9b171427c1512226d5ea402021d8b44ac690.tar.gz
nextcloud-server-14bc9b171427c1512226d5ea402021d8b44ac690.zip
Merge pull request #8095 from nextcloud/webapps-capabilities
Expose navigation entries as API endpoint
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/NavigationManager.php51
-rw-r--r--lib/private/TemplateLayout.php4
-rw-r--r--lib/private/legacy/app.php33
3 files changed, 49 insertions, 39 deletions
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');
}
/**