From 1ea31db81c14686eeae3214361965df5b3c034da Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Mon, 18 Dec 2023 13:59:45 +0100 Subject: [PATCH] MDL-80249 course: Hide secondary menu and add breadcrumb to section page --- blocks/section_links/block_section_links.php | 10 ++--- course/format/classes/base.php | 10 +++++ .../local/content/section/controlmenu.php | 24 ++++++---- .../templates/local/content/section.mustache | 2 +- .../local/content/section/content.mustache | 44 ++++++++++--------- .../local/content/section/header.mustache | 13 +++--- course/format/tests/base_test.php | 22 ++++++++++ .../format/tests/behat/section_page.feature | 3 +- .../content/section/controlmenu.php | 6 +++ .../tests/behat/edit_delete_sections.feature | 6 +-- .../tests/behat/edit_delete_sections.feature | 6 +-- course/section.php | 29 ++++++++---- course/tests/behat/course_controls.feature | 10 ++--- .../behat/paged_course_navigation.feature | 17 +++---- course/tests/behat/sectionzero_title.feature | 12 +++-- course/view.php | 19 +++++++- lib/pagelib.php | 5 ++- lib/tests/moodle_page_test.php | 8 +++- lib/upgrade.txt | 2 + theme/boost/classes/boostnavbar.php | 11 +++-- theme/boost/scss/moodle/course.scss | 13 ++++-- theme/boost/style/moodle.css | 13 ++++-- theme/classic/style/moodle.css | 13 ++++-- 23 files changed, 194 insertions(+), 104 deletions(-) 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 @@ }}