From 8ebf873b6546331321a6333a81e52e2239945a95 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Wed, 30 Aug 2023 00:20:01 +0800 Subject: [PATCH] MDL-79047 grade: Use the gradebook plugin name for the page title * Use the appropriate gradebook plugin string for the page title. * Improve gradebook page titles set by grade_get_plugin_info() by listing the unique identifying information for the page first (e.g. the gradebook plugin name), followed by broader information (Grades + Course name), separating these bits of information using the pipe `|` character. For more information, check out https://www.w3.org/WAI/WCAG21/Techniques/general/G88 --- grade/lib.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/grade/lib.php b/grade/lib.php index 04eb90eb54d..1aa9e9e5b9e 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -770,8 +770,8 @@ function grade_get_plugin_info($courseid, $active_type, $active_plugin) { break; } foreach ($plugins as $plugin) { - if (is_a($plugin, 'grade_plugin_info')) { - if ($active_plugin == $plugin->id) { + if (is_a($plugin, grade_plugin_info::class)) { + if ($plugin_type === $active_type && $active_plugin == $plugin->id) { $plugin_info['strings']['active_plugin_str'] = $plugin->string; } } @@ -880,7 +880,7 @@ class grade_plugin_info { * @param string|null $headerhelpidentifier The help string identifier if required. * @param string|null $headerhelpcomponent The component for the help string. * @param stdClass|null $user The user object for use with the user context header. - * @param actionbar|null $actionbar The actions bar which will be displayed on the page if $shownavigation is set + * @param action_bar|null $actionbar The actions bar which will be displayed on the page if $shownavigation is set * to true. If $actionbar is not explicitly defined, the general action bar * (\core_grades\output\general_action_bar) will be used by default. * @param boolean $showtitle If set to false just show course full name as a title. @@ -922,7 +922,19 @@ function print_grade_page_head(int $courseid, string $active_type, ?string $acti } else { $PAGE->set_pagelayout('admin'); } - $PAGE->set_title(get_string('grades') . ': ' . $stractive_type); + $coursecontext = context_course::instance($courseid); + // Title will be constituted by information starting from the unique identifying information for the page. + if (in_array($active_type, ['report', 'settings'])) { + $uniquetitle = $stractive_plugin; + } else { + $uniquetitle = $stractive_type . ': ' . $stractive_plugin; + } + $titlecomponents = [ + $uniquetitle, + get_string('grades'), + $coursecontext->get_context_name(false), + ]; + $PAGE->set_title(implode(moodle_page::TITLE_SEPARATOR, $titlecomponents)); $PAGE->set_heading($title); $PAGE->set_secondary_active_tab('grades'); @@ -988,8 +1000,7 @@ function print_grade_page_head(int $courseid, string $active_type, ?string $acti echo $output; } - $returnval .= print_natural_aggregation_upgrade_notice($courseid, context_course::instance($courseid), $PAGE->url, - $return); + $returnval .= print_natural_aggregation_upgrade_notice($courseid, $coursecontext, $PAGE->url, $return); if ($return) { return $returnval;