From b9f9aae134a65765d3287e8189a787c70751058b Mon Sep 17 00:00:00 2001 From: Peter Dias Date: Thu, 10 Feb 2022 15:20:11 +0800 Subject: [PATCH] MDL-73462 course: Update visible nodes in a cat context. --- admin/tool/lp/lib.php | 2 ++ lib/classes/navigation/views/secondary.php | 26 ++++++++++++++++------ lib/navigationlib.php | 20 +++++++++-------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/admin/tool/lp/lib.php b/admin/tool/lp/lib.php index e17c031e1c3..1860a549ee9 100644 --- a/admin/tool/lp/lib.php +++ b/admin/tool/lp/lib.php @@ -104,6 +104,7 @@ function tool_lp_extend_navigation_category_settings($navigation, $coursecategor null, new pix_icon('i/competencies', '')); if (isset($settingsnode)) { + $settingsnode->set_force_into_more_menu(true); $navigation->add_node($settingsnode); } } @@ -119,6 +120,7 @@ function tool_lp_extend_navigation_category_settings($navigation, $coursecategor null, new pix_icon('i/competencies', '')); if (isset($settingsnode)) { + $settingsnode->set_force_into_more_menu(true); $navigation->add_node($settingsnode); } } diff --git a/lib/classes/navigation/views/secondary.php b/lib/classes/navigation/views/secondary.php index 16491831e1d..ab6a661b7f1 100644 --- a/lib/classes/navigation/views/secondary.php +++ b/lib/classes/navigation/views/secondary.php @@ -137,9 +137,24 @@ class secondary extends view { * @return array */ protected function get_default_category_mapping(): array { - return []; + return [ + self::TYPE_SETTING => [ + 'edit' => 1, + 'permissions' => 2, + 'roles' => 2.1, + 'checkpermissions' => 2.2, + ] + ]; } + /** + * Define the keys of the course secondary nav nodes that should be forced into the "more" menu by default. + * + * @return array + */ + protected function get_default_category_more_menu_nodes(): array { + return ['addsubcat', 'roles', 'permissions', 'contentbank', 'cohort', 'filters', 'restorecourse']; + } /** * Define the keys of the course secondary nav nodes that should be forced into the "more" menu by default. * @@ -211,6 +226,7 @@ class secondary extends view { case CONTEXT_COURSECAT: $this->headertitle = get_string('categoryheader'); $this->load_category_navigation(); + $defaultmoremenunodes = $this->get_default_category_more_menu_nodes(); break; case CONTEXT_SYSTEM: $this->headertitle = get_string('homeheader'); @@ -659,14 +675,10 @@ class secondary extends view { $settingsnav = $this->page->settingsnav; $mainnode = $settingsnav->find('categorysettings', self::TYPE_CONTAINER); $nodes = $this->get_default_category_mapping(); - $siteadmin = $settingsnav->find('root', self::TYPE_SITE_ADMIN); - // If an admin is viewing a category context then load the site admin menu. - if ($siteadmin) { - $this->load_admin_navigation(); - } else if ($mainnode) { + if ($mainnode) { $url = new \moodle_url('/course/index.php', ['categoryid' => $this->context->instanceid]); - $this->add($this->context->get_context_name(), $url, self::TYPE_CONTAINER, null, 'categorymain'); + $this->add(get_string('category'), $url, self::TYPE_CONTAINER, null, 'categorymain'); // Add the initial nodes. $nodesordered = $this->get_leaf_nodes($mainnode, $nodes); diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 1fe6a79c2f0..ecec4f682f3 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -5418,12 +5418,13 @@ class settings_navigation extends navigation_node { if (can_edit_in_category($catcontext->instanceid)) { $url = new moodle_url('/course/management.php', array('categoryid' => $catcontext->instanceid)); $editstring = get_string('managecategorythis'); - $categorynode->add($editstring, $url, self::TYPE_SETTING, null, 'managecategory', new pix_icon('i/edit', '')); + $node = $categorynode->add($editstring, $url, self::TYPE_SETTING, null, 'managecategory', new pix_icon('i/edit', '')); + $node->set_show_in_secondary_navigation(false); } if (has_capability('moodle/category:manage', $catcontext)) { $editurl = new moodle_url('/course/editcategory.php', array('id' => $catcontext->instanceid)); - $categorynode->add(get_string('editcategorythis'), $editurl, self::TYPE_SETTING, null, 'edit', new pix_icon('i/edit', '')); + $categorynode->add(get_string('settings'), $editurl, self::TYPE_SETTING, null, 'edit', new pix_icon('i/edit', '')); $addsubcaturl = new moodle_url('/course/editcategory.php', array('parent' => $catcontext->instanceid)); $categorynode->add(get_string('addsubcategory'), $addsubcaturl, self::TYPE_SETTING, null, @@ -5449,13 +5450,6 @@ class settings_navigation extends navigation_node { $categorynode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING, null, 'checkpermissions', new pix_icon('i/checkpermissions', '')); } - $cb = new contentbank(); - if ($cb->is_context_allowed($catcontext) - && has_capability('moodle/contentbank:access', $catcontext)) { - $url = new \moodle_url('/contentbank/index.php', ['contextid' => $catcontext->id]); - $categorynode->add(get_string('contentbank'), $url, self::TYPE_CUSTOM, null, 'contentbank', new \pix_icon('i/contentbank', '')); - } - // Add the context locking node. $this->add_context_locking_node($categorynode, $catcontext); @@ -5485,6 +5479,14 @@ class settings_navigation extends navigation_node { } } + $cb = new contentbank(); + if ($cb->is_context_allowed($catcontext) + && has_capability('moodle/contentbank:access', $catcontext)) { + $url = new \moodle_url('/contentbank/index.php', ['contextid' => $catcontext->id]); + $categorynode->add(get_string('contentbank'), $url, self::TYPE_CUSTOM, null, + 'contentbank', new \pix_icon('i/contentbank', '')); + } + return $categorynode; }