From 3152af35131c7ffc4d4f67ebdc0239c9a153eccc Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 19 Mar 2025 16:52:08 +0000 Subject: [PATCH] MDL-84941 course: fix activity button label on end of section. Where the button is rendered after all section content, we should fix the ARIA label attribute to refer to the current section rather than non-existing subsequent activity. --- course/classes/output/activitychooserbutton.php | 3 ++- course/lib.php | 2 +- course/templates/activitychooserbutton.mustache | 6 +++++- course/tests/behat/activity_chooser_plus.feature | 2 ++ lang/en/moodle.php | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/course/classes/output/activitychooserbutton.php b/course/classes/output/activitychooserbutton.php index 93168d33b19..1255dbc6be4 100644 --- a/course/classes/output/activitychooserbutton.php +++ b/course/classes/output/activitychooserbutton.php @@ -48,7 +48,7 @@ class activitychooserbutton implements templatable, renderable { protected section_info $section, /** @var cm_info|null the course module instance */ protected ?cm_info $mod = null, - /** @var sectionreturn|null the section to return to */ + /** @var int|null the section to return to */ protected ?int $sectionreturn = null, /** @var array|null action_link[] the action links */ protected ?array $actionlinks = [], @@ -73,6 +73,7 @@ class activitychooserbutton implements templatable, renderable { return (object)[ 'sectionnum' => $this->section->section, + 'sectionname' => get_section_name($this->section->course, $this->section), 'sectionreturn' => $this->sectionreturn ?? false, 'modid' => $this->mod ? $this->mod->id : false, 'activityname' => $this->mod ? $this->mod->get_formatted_name() : false, diff --git a/course/lib.php b/course/lib.php index 1557e5729bd..f8cdbdfacdd 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1730,7 +1730,7 @@ function move_courses($courseids, $categoryid) { * @see core_courseformat\base::get_section_name() * * @param int|stdClass $courseorid The course to get the section name for (object or just course id) - * @param int|stdClass $section Section object from database or just field course_sections.section + * @param int|stdClass|section_info $section Section object from database or just field course_sections.section * @return string Display name that the course format prefers, e.g. "Week 2" */ function get_section_name($courseorid, $section) { diff --git a/course/templates/activitychooserbutton.mustache b/course/templates/activitychooserbutton.mustache index 3616101f0a5..577875c5a49 100644 --- a/course/templates/activitychooserbutton.mustache +++ b/course/templates/activitychooserbutton.mustache @@ -23,6 +23,7 @@ { "hasactionlinks": false, "sectionnum": 0, + "sectionname": "Section example", "modid": 1, "activityname": "Activity example", "sectionreturn": 0 @@ -44,10 +45,13 @@ data-action="open-addingcontent" {{#modid}} data-beforemod="{{modid}}" + aria-label="{{#str}}insertcontentbefore, core, { "activityname": {{#quote}} {{activityname}} {{/quote}} } {{/str}}" + {{/modid}} + {{^modid}} + aria-label="{{#str}}insertcontentsection, core, { "sectionname": {{#quote}} {{sectionname}} {{/quote}} } {{/str}}" {{/modid}} aria-haspopup="true" aria-expanded="false" - aria-label="{{#str}}insertcontentbefore, core, { "activityname": {{#quote}} {{activityname}} {{/quote}} } {{/str}}" tabindex="0" title="{{#str}}addcontent, core{{/str}}" > diff --git a/course/tests/behat/activity_chooser_plus.feature b/course/tests/behat/activity_chooser_plus.feature index 94827b9276a..a0e40dce831 100644 --- a/course/tests/behat/activity_chooser_plus.feature +++ b/course/tests/behat/activity_chooser_plus.feature @@ -29,6 +29,8 @@ Feature: Use the activity chooser to insert activities anywhere in a section And "Insert content before 'Test Forum'" "button" should not be visible When I hover "Insert content before 'Test Forum'" "button" Then "Insert content before 'Test Forum'" "button" should be visible + And I hover "Insert content in section 'New section'" "button" + Then "Insert content in section 'New section'" "button" should be visible Scenario: The activity chooser can be used to insert modules before existing modules Given I change window size to "large" diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 23eef3ba7ea..a3e9fe6fc0f 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1178,6 +1178,7 @@ $string['indicator:userforumstracking_help'] = 'This indicator represents whethe $string['info'] = 'Information'; $string['inprogress'] = 'In progress'; $string['insertcontentbefore'] = 'Insert content before \'{$a->activityname}\''; +$string['insertcontentsection'] = 'Insert content in section \'{$a->sectionname}\''; $string['insertresourceoractivitybefore'] = 'Insert an activity or resource before \'{$a->activityname}\''; $string['institution'] = 'Institution'; $string['instudentview'] = 'in student view';