From 608a25df01b6f5f9a84e9a31f6a14a0bbe084791 Mon Sep 17 00:00:00 2001 From: ferran Date: Thu, 20 Mar 2025 12:58:43 +0100 Subject: [PATCH] MDL-84940 block_section_links: omit subsections --- blocks/section_links/block_section_links.php | 10 +++++++--- .../tests/behat/block_section_links_course.feature | 13 +++++++++++++ .../tests/behat/show_section_name.feature | 10 ++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/blocks/section_links/block_section_links.php b/blocks/section_links/block_section_links.php index f2c4532f9d4..6ebef5f1234 100644 --- a/blocks/section_links/block_section_links.php +++ b/blocks/section_links/block_section_links.php @@ -111,7 +111,7 @@ class block_section_links extends block_base { $showsectionname = !empty($config->showsectionname) ? true : false; // Prepare an array of sections to create links for. - $sections = array(); + $sections = []; $canviewhidden = has_capability('moodle/course:update', $context); $coursesections = $courseformat->get_sections(); $coursesectionscount = count($coursesections); @@ -121,12 +121,16 @@ class block_section_links extends block_base { continue; } $section = $coursesections[$i]; + // Delegated sections (like subsections) are not listed in the block. + if ($section->get_component_instance() !== null) { + continue; + } if ($section->section && ($section->visible || $canviewhidden)) { - $sections[$i] = (object)array( + $sections[$i] = (object) [ 'section' => $section->section, 'visible' => $section->visible, 'highlight' => false - ); + ]; if ($courseformat->is_section_current($section)) { $sections[$i]->highlight = true; $sectiontojumpto = $section->section; diff --git a/blocks/section_links/tests/behat/block_section_links_course.feature b/blocks/section_links/tests/behat/block_section_links_course.feature index 27ac1516797..d495dedeca6 100644 --- a/blocks/section_links/tests/behat/block_section_links_course.feature +++ b/blocks/section_links/tests/behat/block_section_links_course.feature @@ -60,3 +60,16 @@ Feature: The section links block allows users to quickly navigate around a moodl And I should see "5" in the "Section links" "block" When I follow "5" Then I should see "Test assignment 1" + + Scenario: Subsections numbers are not displayed in the Section links block + Given the following "activity" exists: + | activity | subsection | + | name | Subsection1 | + | course | C1 | + | idnumber | subsection1 | + | section | 1 | + And the following "blocks" exist: + | blockname | contextlevel | reference | pagetypepattern | defaultregion | + | section_links | Course | C1 | course-view-* | side-pre | + When I am on "Course 1" course homepage + Then "21" "link" should not exist in the "Section links" "block" diff --git a/blocks/section_links/tests/behat/show_section_name.feature b/blocks/section_links/tests/behat/show_section_name.feature index 79e36f5bc95..e78fb49efcd 100644 --- a/blocks/section_links/tests/behat/show_section_name.feature +++ b/blocks/section_links/tests/behat/show_section_name.feature @@ -44,3 +44,13 @@ Feature: The Section links block can be configured to display section name in ad And I should see "7" in the "Section links" "block" And I follow "7" And I should see "First assignment" + + Scenario: Subsections names are not displayed in the Section links block + Given the following "activity" exists: + | activity | subsection | + | name | Subsection1 | + | course | C1 | + | idnumber | subsection1 | + | section | 1 | + When I am on the "Course 1" course page logged in as student1 + Then I should not see "Subsection1" in the "Section links" "block"