diff --git a/.upgradenotes/MDL-87929-2026021310531011.yml b/.upgradenotes/MDL-87929-2026021310531011.yml new file mode 100644 index 00000000000..e7c4c7735e6 --- /dev/null +++ b/.upgradenotes/MDL-87929-2026021310531011.yml @@ -0,0 +1,9 @@ +issueNumber: MDL-87929 +notes: + theme: + - message: >- + The `core_courseformat\base` class now includes + `set_show_restrictions_expanded()` and `get_show_restrictions_expanded()` + to allow course formats to define whether restrictions are displayed + as expanded (defaulting to collapsed). + type: improved diff --git a/public/availability/tests/behat/display_availability.feature b/public/availability/tests/behat/display_availability.feature index 5655baaa054..38a7ba90de7 100644 --- a/public/availability/tests/behat/display_availability.feature +++ b/public/availability/tests/behat/display_availability.feature @@ -196,10 +196,15 @@ Feature: Display availability for activities and sections And I am on the "C1" "Course" page logged in as "teacher1" And I turn editing mode on And I add the "Navigation" block if not present - # Add a restriction to section 1 (visible to students). + # Add a couple of restrictions to section 1 (visible to students). And I edit the section "1" And I set the following fields to these values: | Access restrictions | Grouping: GX1 | + And I expand all fieldsets + And I press "Add restriction..." + And I click on "Date" "button" in the "Add restriction..." "dialogue" + And I set the field "direction" to "until" + And I set the field "x[year]" to "2020" And I press "Save changes" # Change to student view. And I am on the "Course 1" "Course" page logged in as "student1" @@ -207,7 +212,9 @@ Feature: Display availability for activities and sections When I click on "Section 1" "link" in the "Navigation" "block" # Section 1 should be visible and show info. And I should see "Section 1" in the "page-header" "region" - And I should see "Not available unless" in the "region-main" "region" + And I should see "It is before end of" in the "region-main" "region" + And I should not see "Show more" in the "region-main" "region" + And I should not see "Show less" in the "region-main" "region" And "Page 1" "link" should not exist in the "region-main" "region" # Check the logs. And I am on the "C1" "Course" page logged in as "teacher1" @@ -234,9 +241,14 @@ Feature: Display availability for activities and sections | name | course | idnumber | | GX1 | C1 | GXI1 | And I am on the "Glossary 1" "glossary activity editing" page logged in as "teacher1" - # Add a restriction to Glossary 1 (visible to students). + # Add a couple of restrictions to Glossary 1 (visible to students). And I set the following fields to these values: | Access restrictions | Grouping: GX1 | + And I expand all fieldsets + And I press "Add restriction..." + And I click on "Date" "button" in the "Add restriction..." "dialogue" + And I set the field "direction" to "until" + And I set the field "x[year]" to "2020" And I press "Save and return to course" And I turn editing mode on And I add the "Navigation" block if not present @@ -247,7 +259,9 @@ Feature: Display availability for activities and sections When I click on "Glossary 1" "link" in the "Navigation" "block" # Glossary 1 should be visible and show info. Then I should see "Glossary 1" in the "page-header" "region" - And I should see "Not available unless" in the "region-main" "region" + And I should see "It is before end of" in the "region-main" "region" + And I should not see "Show more" in the "region-main" "region" + And I should not see "Show less" in the "region-main" "region" And "Add a new entry" "link" should not exist # Check the logs. And I am on the "C1" "Course" page logged in as "teacher1" diff --git a/public/course/classes/route/controller/restricted_section.php b/public/course/classes/route/controller/restricted_section.php index 82db465ae28..2082792fdf8 100644 --- a/public/course/classes/route/controller/restricted_section.php +++ b/public/course/classes/route/controller/restricted_section.php @@ -63,6 +63,8 @@ class restricted_section { $context = \context_course::instance($course->id); $format = course_get_format($course->id); $format->set_sectionid($section->id); + // We always want to show the restrictions expanded in the restricted section page. + $format->set_show_restrictions_expanded(true); $outputclass = $format->get_output_classname('content'); $sectionoutput = new $outputclass($format); $PAGE->set_url('/course/section.php', ['id' => $section->id]); diff --git a/public/course/format/classes/base.php b/public/course/format/classes/base.php index b01d07be1a8..8d491217e06 100644 --- a/public/course/format/classes/base.php +++ b/public/course/format/classes/base.php @@ -81,6 +81,8 @@ abstract class base { protected $singlesection = null; /** @var int|null the sectionid when a single section is selected, null when multiple sections are displayed. */ protected $singlesectionid = null; + /** @var bool Whether restrictions should be expanded. */ + protected $showrestrictionsexpanded = false; /** @var course_modinfo the current course modinfo, please use course_format::get_modinfo() */ private $modinfo = null; /** @var array cached instances */ @@ -664,6 +666,24 @@ abstract class base { return $this->singlesectionid; } + /** + * Set whether restrictions should be expanded. + * + * @param bool $expanded True if restrictions should be expanded, false otherwise. + */ + public function set_show_restrictions_expanded(bool $expanded): void { + $this->showrestrictionsexpanded = $expanded; + } + + /** + * Get whether restrictions should be expanded. + * + * @return bool True if restrictions should be expanded, false otherwise. + */ + public function get_show_restrictions_expanded(): bool { + return $this->showrestrictionsexpanded; + } + /** * Set the current section number to display. * Some formats has the hability to swith from one section to multiple sections per page. diff --git a/public/course/format/classes/output/local/content/section/availability.php b/public/course/format/classes/output/local/content/section/availability.php index 47a4f4df71f..bbac32cdf30 100644 --- a/public/course/format/classes/output/local/content/section/availability.php +++ b/public/course/format/classes/output/local/content/section/availability.php @@ -197,6 +197,10 @@ class availability implements named_templatable, renderable { } } + if ($this->format->get_show_restrictions_expanded()) { + $data->showrestrictionsexpanded = true; + } + return $data; } diff --git a/public/course/format/templates/local/content/availability.mustache b/public/course/format/templates/local/content/availability.mustache index 681769f9ff3..2174e89b5dc 100644 --- a/public/course/format/templates/local/content/availability.mustache +++ b/public/course/format/templates/local/content/availability.mustache @@ -34,13 +34,16 @@ {{/excerpt}} {{#excerpt}} {{< core/showmore }} + {{$defaultstatus}} + {{^showrestrictionsexpanded}} collapsed {{/showrestrictionsexpanded}} + {{/defaultstatus}} {{$collapsedcontent}} {{#pix}}t/unlock, core{{/pix}} {{{excerpt}}} ... {{/collapsedcontent}} {{$expandedcontent}} {{#pix}}t/unlock, core{{/pix}} {{{text}}} {{/expandedcontent}} - {{$buttonextraclasses}}fw-bold{{/buttonextraclasses}} + {{$buttonextraclasses}}fw-bold {{#showrestrictionsexpanded}} d-none {{/showrestrictionsexpanded}}{{/buttonextraclasses}} {{$collapsedextraclasses}}text-truncate pe-2 {{#editing}}mt-2{{/editing}}{{/collapsedextraclasses}} {{$expandedextraclasses}} {{^editing}}py-2{{/editing}} diff --git a/public/course/format/templates/local/content/cm/restricted.mustache b/public/course/format/templates/local/content/cm/restricted.mustache index 59f8044a7bb..42ba68a1e4f 100644 --- a/public/course/format/templates/local/content/cm/restricted.mustache +++ b/public/course/format/templates/local/content/cm/restricted.mustache @@ -61,7 +61,10 @@ {{! Availability }} {{#modavailability}} {{$ core_courseformat/local/content/cm/availability }} - {{> core_courseformat/local/content/cm/availability }} + {{< core_courseformat/local/content/cm/availability }} + {{$buttonextraclasses}} d-none {{/buttonextraclasses}} + {{$defaultstatus}} expanded {{/defaultstatus}} + {{/core_courseformat/local/content/cm/availability }} {{/ core_courseformat/local/content/cm/availability }} {{/modavailability}} diff --git a/public/lib/templates/showmore.mustache b/public/lib/templates/showmore.mustache index ecd339c1b36..e95a51c600a 100644 --- a/public/lib/templates/showmore.mustache +++ b/public/lib/templates/showmore.mustache @@ -28,7 +28,7 @@ "expandedextraclasses": "bg-secondary" } }} -