Skip to content

Commit

Permalink
In secondary nav, add course and activity nodes for single activity f…
Browse files Browse the repository at this point in the history
…ormat ASAP so we can see them while debugging
  • Loading branch information
cameron1729 committed Sep 3, 2024
1 parent f390155 commit 1f81e40
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lib/classes/navigation/views/secondary.php
Original file line number Diff line number Diff line change
Expand Up @@ -1083,21 +1083,27 @@ protected function load_single_activity_course_navigation(): void {

// Create 'Course' navigation node.
$coursesecondarynode = navigation_node::create(get_string('course'), null, self::TYPE_COURSE, null, 'course');

// Add the node ASAP so that we can see its state during navigation debugging.
// If it needs to be removed then we will remove it later. See the if block
// just below.
$this->add_node($coursesecondarynode);
$this->load_course_navigation($coursesecondarynode);

// This is required to force the template to output these items within a dropdown menu.
$coursesecondarynode->showchildreninsubmenu = true;

if (count($coursesecondarynode->children) === 0) {
$coursesecondarynode->showchildreninsubmenu = false;
$coursesecondarynode->remove();
}

// Remove the unnecessary 'Course' child node generated in load_course_navigation().
$coursehomenode = $coursesecondarynode->find('coursehome', self::TYPE_COURSE);
if (!empty($coursehomenode)) {
$coursehomenode->remove();
}

// Add the 'Course' node to the secondary navigation only if this node has children nodes.
if (count($coursesecondarynode->children) > 0) {
$this->add_node($coursesecondarynode);
// Once all the items have been added to the 'Course' secondary navigation node, set the 'showchildreninsubmenu'
// property to true. This is required to force the template to output these items within a dropdown menu.
$coursesecondarynode->showchildreninsubmenu = true;
}

// Create 'Activity' navigation node.
$activitysecondarynode = navigation_node::create(get_string('activity'), null, self::TYPE_ACTIVITY, null, 'activity');

Expand All @@ -1120,14 +1126,15 @@ protected function load_single_activity_course_navigation(): void {
$page->set_url(new \moodle_url('/mod/' . $page->activityname . '/view.php', ['id' => $page->cm->id]));
}

// As before, add ASAP to be able to inspect during debugging.
$this->add_node($activitysecondarynode);
$this->load_module_navigation($page->settingsnav, $activitysecondarynode);

// Add the 'Activity' node to the secondary navigation only if this node has more that one child node.
if (count($activitysecondarynode->children) > 1) {
// Set the 'showchildreninsubmenu' property to true to later output the the module navigation items within
// a dropdown menu.
$activitysecondarynode->showchildreninsubmenu = true;
$this->add_node($activitysecondarynode);
if ($this->context instanceof \context_module) {
$this->page->set_secondary_active_tab($activitysecondarynode->key);
}
Expand Down

0 comments on commit 1f81e40

Please sign in to comment.