diff --git a/blocks/section_links/block_section_links.php b/blocks/section_links/block_section_links.php index f7e555e5360..347a127a768 100644 --- a/blocks/section_links/block_section_links.php +++ b/blocks/section_links/block_section_links.php @@ -44,10 +44,12 @@ class block_section_links extends block_base { * @return array */ public function applicable_formats() { - return array( + return [ 'course-view-weeks' => true, - 'course-view-topics' => true - ); + 'course-view-topics' => true, + 'section-view-weeks' => true, + 'section-view-topics' => true, + ]; } /** @@ -179,5 +181,3 @@ class block_section_links extends block_base { ]; } } - - diff --git a/course/format/classes/base.php b/course/format/classes/base.php index 3a64d6dd912..2d897626f22 100644 --- a/course/format/classes/base.php +++ b/course/format/classes/base.php @@ -2028,4 +2028,14 @@ abstract class base { public function get_required_jsfiles(): array { return []; } + + /** + * Determines whether section items can be removed from the navigation, just like the breadcrumb feature seen on activity pages. + * By default, it returns false but can be overridden by the course format to change the behaviour. + * + * @return bool True if sections can be removed, false otherwise. + */ + public function can_sections_be_removed_from_navigation(): bool { + return false; + } } diff --git a/course/format/classes/output/local/content/section/controlmenu.php b/course/format/classes/output/local/content/section/controlmenu.php index a446a779a8c..63f2fa40d5f 100644 --- a/course/format/classes/output/local/content/section/controlmenu.php +++ b/course/format/classes/output/local/content/section/controlmenu.php @@ -119,7 +119,7 @@ class controlmenu implements named_templatable, renderable { * @return array of edit control items */ public function section_control_items() { - global $USER; + global $USER, $PAGE; $format = $this->format; $section = $this->section; @@ -135,13 +135,18 @@ class controlmenu implements named_templatable, renderable { $baseurl = course_get_url($course, $sectionreturn); $baseurl->param('sesskey', sesskey()); - $controls['view'] = [ - 'url' => new moodle_url('/course/section.php', ['id' => $section->id]), - 'icon' => 'i/viewsection', - 'name' => get_string('view'), - 'pixattr' => ['class' => ''], - 'attr' => ['class' => 'icon view'], - ]; + $controls = []; + + // Only show the view link if we are not already in the section view page. + if ($PAGE->pagetype !== 'section-view-' . $course->format) { + $controls['view'] = [ + 'url' => new moodle_url('/course/section.php', ['id' => $section->id]), + 'icon' => 'i/viewsection', + 'name' => get_string('view'), + 'pixattr' => ['class' => ''], + 'attr' => ['class' => 'icon view'], + ]; + } if (!$isstealth && has_capability('moodle/course:update', $coursecontext, $user)) { $params = ['id' => $section->id]; @@ -177,6 +182,9 @@ class controlmenu implements named_templatable, renderable { if ($section->section) { $url = clone($baseurl); + if (!is_null($sectionreturn)) { + $url->param('sectionid', $format->get_sectionid()); + } if (!$isstealth) { if (has_capability('moodle/course:sectionvisibility', $coursecontext, $user)) { $strhidefromothers = get_string('hidefromothers', 'format_' . $course->format); diff --git a/course/format/templates/local/content/section.mustache b/course/format/templates/local/content/section.mustache index 706d40e8408..0e33a56e7ec 100644 --- a/course/format/templates/local/content/section.mustache +++ b/course/format/templates/local/content/section.mustache @@ -88,7 +88,7 @@ }}