MDL-56993 boost: Fix navigation for singleactivity format
The single activity course format has no course front page, so we need to make a special case for it so it's possible to get to the course admin menu and put the course nodes in the flat navigation.
This commit is contained in:
@@ -3724,8 +3724,16 @@ class flat_navigation extends navigation_node_collection {
|
||||
$flat = new flat_navigation_node(navigation_node::create($course->shortname, $url), 0);
|
||||
$flat->key = 'coursehome';
|
||||
|
||||
$courseformat = course_get_format($course);
|
||||
$coursenode = $PAGE->navigation->find_active_node();
|
||||
while (!empty($coursenode) && ($coursenode->type != navigation_node::TYPE_COURSE)) {
|
||||
$targettype = navigation_node::TYPE_COURSE;
|
||||
|
||||
// Single activity format has no course node - the course node is swapped for the activity node.
|
||||
if (!$courseformat->has_view_page()) {
|
||||
$targettype = navigation_node::TYPE_ACTIVITY;
|
||||
}
|
||||
|
||||
while (!empty($coursenode) && ($coursenode->type != $targettype)) {
|
||||
$coursenode = $coursenode->parent;
|
||||
}
|
||||
// There is one very strange page in mod/feedback/view.php which thinks it is both site and course
|
||||
|
||||
@@ -545,53 +545,94 @@ class core_renderer extends \core_renderer {
|
||||
public function context_header_settings_menu() {
|
||||
$context = $this->page->context;
|
||||
$menu = new action_menu();
|
||||
if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
// Get the course admin node from the settings navigation.
|
||||
$items = $this->page->navbar->get_items();
|
||||
$node = end($items);
|
||||
$settingsnode = false;
|
||||
if (!empty($node) && $node->key === 'home') {
|
||||
$settingsnode = $this->page->settingsnav->find('frontpage', navigation_node::TYPE_SETTING);
|
||||
if ($settingsnode) {
|
||||
// Build an action menu based on the visible nodes from this navigation tree.
|
||||
$skipped = $this->build_action_menu_from_navigation($menu, $settingsnode, false, true);
|
||||
|
||||
// We only add a list to the full settings menu if we didn't include every node in the short menu.
|
||||
if ($skipped) {
|
||||
$text = get_string('morenavigationlinks');
|
||||
$url = new moodle_url('/course/admin.php', array('courseid' => $this->page->course->id));
|
||||
$link = new action_link($url, $text, null, null, new pix_icon('t/edit', $text));
|
||||
$menu->add_secondary_action($link);
|
||||
}
|
||||
}
|
||||
} else if (!empty($node) &&
|
||||
($node->type == navigation_node::TYPE_COURSE || $node->type == navigation_node::TYPE_SECTION)) {
|
||||
$settingsnode = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE);
|
||||
if ($settingsnode) {
|
||||
// Build an action menu based on the visible nodes from this navigation tree.
|
||||
$skipped = $this->build_action_menu_from_navigation($menu, $settingsnode, false, true);
|
||||
$items = $this->page->navbar->get_items();
|
||||
$currentnode = end($items);
|
||||
|
||||
// We only add a list to the full settings menu if we didn't include every node in the short menu.
|
||||
if ($skipped) {
|
||||
$text = get_string('morenavigationlinks');
|
||||
$url = new moodle_url('/course/admin.php', array('courseid' => $this->page->course->id));
|
||||
$link = new action_link($url, $text, null, null, new pix_icon('t/edit', $text));
|
||||
$menu->add_secondary_action($link);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ($context->contextlevel == CONTEXT_USER) {
|
||||
$items = $this->page->navbar->get_items();
|
||||
$node = end($items);
|
||||
if (!empty($node) && ($node->key === 'myprofile')) {
|
||||
// Get the course admin node from the settings navigation.
|
||||
$node = $this->page->settingsnav->find('useraccount', navigation_node::TYPE_CONTAINER);
|
||||
if ($node) {
|
||||
// Build an action menu based on the visible nodes from this navigation tree.
|
||||
$this->build_action_menu_from_navigation($menu, $node);
|
||||
$showcoursemenu = false;
|
||||
$showfrontpagemenu = false;
|
||||
$showusermenu = false;
|
||||
|
||||
// We are on the course home page.
|
||||
if (($context->contextlevel == CONTEXT_COURSE) &&
|
||||
!empty($currentnode) &&
|
||||
($currentnode->type == navigation_node::TYPE_COURSE || $currentnode->type == navigation_node::TYPE_SECTION)) {
|
||||
$showcoursemenu = true;
|
||||
}
|
||||
|
||||
$courseformat = course_get_format($this->page->course);
|
||||
// This is a single activity course format, always show the course menu on the activity main page.
|
||||
if ($context->contextlevel == CONTEXT_MODULE &&
|
||||
!$courseformat->has_view_page()) {
|
||||
|
||||
$this->page->navigation->initialise();
|
||||
$activenode = $this->page->navigation->find_active_node();
|
||||
// If the settings menu has been forced then show the menu.
|
||||
if ($this->page->is_settings_menu_forced()) {
|
||||
$showcoursemenu = true;
|
||||
} else if (!empty($activenode) && ($activenode->type == navigation_node::TYPE_ACTIVITY ||
|
||||
$activenode->type == navigation_node::TYPE_RESOURCE)) {
|
||||
|
||||
// We only want to show the menu on the first page of the activity. This means
|
||||
// the breadcrumb has no additional nodes.
|
||||
if ($currentnode && ($currentnode->key == $activenode->key && $currentnode->type == $activenode->type)) {
|
||||
$showcoursemenu = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is the site front page.
|
||||
if ($context->contextlevel == CONTEXT_COURSE &&
|
||||
!empty($currentnode) &&
|
||||
$currentnode->key === 'home') {
|
||||
$showfrontpagemenu = true;
|
||||
}
|
||||
|
||||
// This is the user profile page.
|
||||
if ($context->contextlevel == CONTEXT_USER &&
|
||||
!empty($currentnode) &&
|
||||
($currentnode->key === 'myprofile')) {
|
||||
$showusermenu = true;
|
||||
}
|
||||
|
||||
|
||||
if ($showfrontpagemenu) {
|
||||
$settingsnode = $this->page->settingsnav->find('frontpage', navigation_node::TYPE_SETTING);
|
||||
if ($settingsnode) {
|
||||
// Build an action menu based on the visible nodes from this navigation tree.
|
||||
$skipped = $this->build_action_menu_from_navigation($menu, $settingsnode, false, true);
|
||||
|
||||
// We only add a list to the full settings menu if we didn't include every node in the short menu.
|
||||
if ($skipped) {
|
||||
$text = get_string('morenavigationlinks');
|
||||
$url = new moodle_url('/course/admin.php', array('courseid' => $this->page->course->id));
|
||||
$link = new action_link($url, $text, null, null, new pix_icon('t/edit', $text));
|
||||
$menu->add_secondary_action($link);
|
||||
}
|
||||
}
|
||||
} else if ($showcoursemenu) {
|
||||
$settingsnode = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE);
|
||||
if ($settingsnode) {
|
||||
// Build an action menu based on the visible nodes from this navigation tree.
|
||||
$skipped = $this->build_action_menu_from_navigation($menu, $settingsnode, false, true);
|
||||
|
||||
// We only add a list to the full settings menu if we didn't include every node in the short menu.
|
||||
if ($skipped) {
|
||||
$text = get_string('morenavigationlinks');
|
||||
$url = new moodle_url('/course/admin.php', array('courseid' => $this->page->course->id));
|
||||
$link = new action_link($url, $text, null, null, new pix_icon('t/edit', $text));
|
||||
$menu->add_secondary_action($link);
|
||||
}
|
||||
}
|
||||
} else if ($showusermenu) {
|
||||
// Get the course admin node from the settings navigation.
|
||||
$settingsnode = $this->page->settingsnav->find('useraccount', navigation_node::TYPE_CONTAINER);
|
||||
if ($settingsnode) {
|
||||
// Build an action menu based on the visible nodes from this navigation tree.
|
||||
$this->build_action_menu_from_navigation($menu, $settingsnode);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($menu);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user