Skip to content

Commit

Permalink
MDL-77690 mod_lesson: Lesson accessibility fixes
Browse files Browse the repository at this point in the history
* Set the heading levels of lesson pages appropriately to avoid skipped
heading issues.
* Add appropriate labels for tertiary navigation select menus.
  • Loading branch information
junpataleta committed Jun 30, 2023
1 parent 213223d commit 14d4f0a
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 17 deletions.
7 changes: 6 additions & 1 deletion mod/lesson/classes/output/edit_action_area.php
Expand Up @@ -60,6 +60,7 @@ public function __construct(int $cmid, moodle_url $currenturl) {
* @return array Said data.
*/
public function export_for_template(\renderer_base $output): array {
global $PAGE;

$viewurl = new moodle_url('/mod/lesson/edit.php', ['id' => $this->cmid, 'mode' => 'collapsed']);
$fullviewurl = new moodle_url('/mod/lesson/edit.php', ['id' => $this->cmid, 'mode' => 'full']);
Expand All @@ -69,14 +70,18 @@ public function export_for_template(\renderer_base $output): array {
];

$selectmenu = new \url_select($menu, $this->currenturl->out(false), null, 'mod_lesson_navigation_select');
$selectmenu->label = get_string('displaymode', 'mod_lesson');
$selectmenu->labelattributes = ['class' => 'sr-only'];

$headinglevel = $PAGE->activityheader->get_heading_level();
return [
'back' => [
'text' => get_string('back', 'core'),
'link' => (new moodle_url('/mod/lesson/view.php', ['id' => $this->cmid]))->out(false)
],
'viewselect' => $selectmenu->export_for_template($output),
'heading' => get_string('editinglesson', 'mod_lesson')
'heading' => get_string('editinglesson', 'mod_lesson'),
'headinglevel' => $headinglevel,
];
}
}
8 changes: 7 additions & 1 deletion mod/lesson/classes/output/override_action_menu.php
Expand Up @@ -69,7 +69,10 @@ protected function create_override_select_menu(): \url_select {
$userlink->out(false) => get_string('useroverrides', 'mod_lesson'),
$grouplink->out(false) => get_string('groupoverrides', 'mod_lesson'),
];
return new \url_select($menu, $this->currenturl->out(false), null, 'mod_lesson_override_select');
$selectmenu = new \url_select($menu, $this->currenturl->out(false), null, 'mod_lesson_override_select');
$selectmenu->label = get_string('manageoverrides', 'mod_lesson');
$selectmenu->labelattributes = ['class' => 'sr-only'];
return $selectmenu;
}

/**
Expand All @@ -79,6 +82,8 @@ protected function create_override_select_menu(): \url_select {
* @return array Said data.
*/
public function export_for_template(\renderer_base $output): array {
global $PAGE;

$type = $this->currenturl->get_param('mode');
if ($type == 'user') {
$text = get_string('addnewuseroverride', 'mod_lesson');
Expand All @@ -100,6 +105,7 @@ public function export_for_template(\renderer_base $output): array {
];
}
$data['heading'] = get_string($type == 'user' ? 'useroverrides' : 'groupoverrides', 'mod_lesson');
$data['headinglevel'] = $PAGE->activityheader->get_heading_level();
return $data;
}
}
8 changes: 7 additions & 1 deletion mod/lesson/classes/output/report_action_menu.php
Expand Up @@ -60,16 +60,22 @@ public function __construct(int $lessonid, moodle_url $url) {
* @return array The data for the template.
*/
public function export_for_template(\renderer_base $output): array {
global $PAGE;

$overviewlink = new moodle_url('/mod/lesson/report.php', ['id' => $this->lessonid, 'action' => 'reportoverview']);
$fulllink = new moodle_url('/mod/lesson/report.php', ['id' => $this->lessonid, 'action' => 'reportdetail']);
$menu = [
$overviewlink->out(false) => get_string('overview', 'mod_lesson'),
$fulllink->out(false) => get_string('detailedstats', 'mod_lesson')
];
$reportselect = new \url_select($menu, $this->url->out(false), null, 'lesson-report-select');
$reportselect->label = get_string('selectreport', 'mod_lesson');
$reportselect->labelattributes = ['class' => 'sr-only'];

$data = [
'reportselect' => $reportselect->export_for_template($output),
'heading' => $menu[$reportselect->selected] ?? ''
'heading' => $menu[$reportselect->selected] ?? '',
'headinglevel' => $PAGE->activityheader->get_heading_level(),
];
return $data;
}
Expand Down
3 changes: 2 additions & 1 deletion mod/lesson/import.php
Expand Up @@ -63,7 +63,8 @@
]);
$PAGE->add_body_class('limitedwidth');
echo $OUTPUT->header();
echo $OUTPUT->heading_with_help($strimportquestions, 'importquestions', 'lesson', '', '', 3);
$headinglevel = $PAGE->activityheader->get_heading_level();
echo $OUTPUT->heading_with_help($strimportquestions, 'importquestions', 'lesson', '', '', $headinglevel);

if ($data = $mform->get_data()) {

Expand Down
3 changes: 3 additions & 0 deletions mod/lesson/lang/en/lesson.php
Expand Up @@ -168,6 +168,7 @@
$string['displayleftif_help'] = 'This setting determines whether a student must obtain a certain grade before viewing the lesson menu. This forces the student to go through the entire lesson on their first attempt, then after obtaining the required grade they can use the menu for review.';
$string['displayleftmenu'] = 'Display menu';
$string['displayleftmenu_help'] = 'If enabled, a menu allowing users to navigate through the list of pages is displayed.';
$string['displaymode'] = 'Display mode';
$string['displayofgrade'] = 'Display of grade (for students only)';
$string['displayreview'] = 'Provide option to try a question again';
$string['displayreview_help'] = 'If enabled, when a question is answered incorrectly, the student is given the option to try it again for no point credit, or continue with the lesson. If the student clicks to move on to another question then the selected (wrong) answer will be followed. By default wrong answer jumps are set to "this page" and have a score of 0, so it is recommended that you set the wrong answer jump to a different page to avoid confusion with your students.';
Expand Down Expand Up @@ -318,6 +319,7 @@
$string['loginfail'] = 'Login failed, please try again...';
$string['lowscore'] = 'Low score';
$string['lowtime'] = 'Low time';
$string['manageoverrides'] = 'Manage overrides';
$string['manualgrading'] = 'Grade essays';
$string['matchesanswer'] = 'Matches with answer';
$string['matching'] = 'Matching';
Expand Down Expand Up @@ -542,6 +544,7 @@
$string['secondpluswrong'] = 'Not quite. Would you like to try again?';
$string['selectaqtype'] = 'Select a question type';
$string['selectallattempts'] = 'Select all attempts';
$string['selectreport'] = 'Select report';
$string['sent'] = 'Sent';
$string['shortanswer'] = 'Short answer';
$string['showanunansweredpage'] = 'Show an unanswered page';
Expand Down
3 changes: 2 additions & 1 deletion mod/lesson/lesson.php
Expand Up @@ -81,7 +81,8 @@
$title = $DB->get_field("lesson_pages", "title", array("id" => $pageid));

echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('moving', 'lesson', format_String($title)));
echo $OUTPUT->heading(get_string("moving", "lesson", format_string($title)), 3);
$headinglevel = $PAGE->activityheader->get_heading_level();
echo $OUTPUT->heading(get_string("moving", "lesson", format_string($title)), $headinglevel);

$params = array ("lessonid" => $lesson->id, "prevpageid" => 0);
if (!$page = $DB->get_record_select("lesson_pages", "lessonid = :lessonid AND prevpageid = :prevpageid", $params)) {
Expand Down
6 changes: 4 additions & 2 deletions mod/lesson/pagetypes/branchtable.php
Expand Up @@ -113,8 +113,10 @@ public function display($renderer, $attempt) {
if ($this->lesson->slideshow) {
$output .= $renderer->slideshow_start($this->lesson);
}
// We are using level 3 header because the page title is a sub-heading of lesson title (MDL-30911).
$output .= $renderer->heading(format_string($this->properties->title), 3);

// The heading level depends on whether the theme's activity header displays a heading (usually the activity name).
$headinglevel = $PAGE->activityheader->get_heading_level();
$output .= $renderer->heading(format_string($this->properties->title), $headinglevel);
$output .= $renderer->box($this->get_contents(), 'contents');

$buttons = array();
Expand Down
8 changes: 4 additions & 4 deletions mod/lesson/renderer.php
Expand Up @@ -368,10 +368,10 @@ public function add_page_links(lesson $lesson, $prevpageid=false) {
* @return string
*/
public function add_first_page_links(lesson $lesson) {
global $CFG;
$prevpageid = 0;

$output = $this->output->heading(get_string("whatdofirst", "lesson"), 3);
$headinglevel = $this->page->activityheader->get_heading_level(3);
$output = $this->output->heading(get_string("whatdofirst", "lesson"), $headinglevel);
$links = array();

$importquestionsurl = new moodle_url('/mod/lesson/import.php',array('id'=>$this->page->cm->id, 'pageid'=>$prevpageid));
Expand Down Expand Up @@ -567,8 +567,8 @@ public function display_eol_page(lesson $lesson, $data) {
}

if ($data->gradelesson) {
// We are using level 3 header because the page title is a sub-heading of lesson title (MDL-30911).
$output .= $this->heading(get_string("congratulations", "lesson"), 3);
$headinglevel = $this->page->activityheader->get_heading_level();
$output .= $this->heading(get_string("congratulations", "lesson"), $headinglevel);
$output .= $this->box_start('generalbox boxaligncenter');
}

Expand Down
6 changes: 4 additions & 2 deletions mod/lesson/templates/edit_action_area.mustache
Expand Up @@ -64,7 +64,9 @@
]}],
"disabled": false,
"title": "Some cool title"
}
},
"headinglevel": 3,
"heading": "Some heading"
}

}}
Expand All @@ -80,4 +82,4 @@
{{/viewselect}}
</div>
</div>
<h3>{{heading}}</h3>
<h{{headinglevel}}>{{heading}}</h{{headinglevel}}>
6 changes: 4 additions & 2 deletions mod/lesson/templates/override_action_menu.mustache
Expand Up @@ -64,7 +64,9 @@
"addoverride": {
"link": "https://moodle.org",
"text": "Add override"
}
},
"headinglevel": 3,
"heading": "Some heading"
}

}}
Expand All @@ -82,4 +84,4 @@
{{/addoverride}}
</div>
</div>
<h3>{{heading}}</h3>
<h{{headinglevel}}>{{heading}}</h{{headinglevel}}>
6 changes: 4 additions & 2 deletions mod/lesson/templates/report_action_menu.mustache
Expand Up @@ -58,7 +58,9 @@
{"name": "Item 4", "isgroup": false, "value": "4"}
]}],
"disabled": false,
"title": "Some cool title"
"title": "Some cool title",
"headinglevel": 3,
"heading": "Some heading"
}

}}
Expand All @@ -71,4 +73,4 @@
</div>
{{/reportselect}}
</div>
<h3>{{heading}}</h3>
<h{{headinglevel}}>{{heading}}</h{{headinglevel}}>

0 comments on commit 14d4f0a

Please sign in to comment.