MDL-73462 course: Update visible nodes in a cat context.

This commit is contained in:
Peter Dias 2022-02-10 15:20:11 +08:00
parent f1959af7f6
commit b9f9aae134
3 changed files with 32 additions and 16 deletions

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;
}