MDL-79045 grade: Don't enclose grade user_heading in $OUTPUT->heading()

Do not enclose \core_grades_renderer::user_heading() in
$OUTPUT->heading() and enclose the user's name in the user heading in
<h2> tags instead.
- Having <div> inside <h2> results in errors in HTML validation.
- Enclosing the whole user heading in <h2> results in the other
elements in the user heading (Message, Add to contacts) to be announced
to screen readers which can result in confusion.
This commit is contained in:
Jun Pataleta 2023-08-30 20:21:53 +08:00
parent 9bfcd77d51
commit e3633dc719
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
3 changed files with 9 additions and 11 deletions

View File

@ -889,7 +889,7 @@ class grade_plugin_info {
function print_grade_page_head(int $courseid, string $active_type, ?string $active_plugin = null, string|bool $heading = false,
bool $return = false, $buttons = false, bool $shownavigation = true, ?string $headerhelpidentifier = null,
?string $headerhelpcomponent = null, ?stdClass $user = null, ?action_bar $actionbar = null, $unused = null) {
global $CFG, $OUTPUT, $PAGE;
global $CFG, $OUTPUT, $PAGE, $USER;
if ($unused !== null) {
debugging('Deprecated argument passed to ' . __FUNCTION__, DEBUG_DEVELOPER);
@ -960,7 +960,10 @@ function print_grade_page_head(int $courseid, string $active_type, ?string $acti
$output = $OUTPUT->heading_with_help($heading, $headerhelpidentifier, $headerhelpcomponent);
} else if (isset($user)) {
$renderer = $PAGE->get_renderer('core_grades');
$output = $OUTPUT->heading($renderer->user_heading($user, $courseid));
// If the user is viewing their own grade report, no need to show the "Message"
// and "Add to contact" buttons in the user heading.
$showuserbuttons = $user->id != $USER->id;
$output = $renderer->user_heading($user, $courseid, $showuserbuttons);
} else if (!empty($heading)) {
$output = $OUTPUT->heading($heading);
}

View File

@ -164,7 +164,7 @@ if (has_capability('moodle/grade:viewall', $context)) {
$report = new gradereport_user\report\user($courseid, $gpr, $context, $user->id, $viewasuser);
$userheading = $gradesrenderer->user_heading($report->user, $courseid, false);
echo $OUTPUT->heading($userheading);
echo $userheading;
if ($report->fill_table()) {
echo $report->print_table(true);
@ -178,9 +178,7 @@ if (has_capability('moodle/grade:viewall', $context)) {
$report = new gradereport_user\report\user($courseid, $gpr, $context, $userid, $viewasuser);
$actionbar = new \gradereport_user\output\action_bar($context, $userview, $report->user->id, $currentgroup);
print_grade_page_head($courseid, 'report', 'user',
$gradesrenderer->user_heading($report->user, $courseid),
false, false, true, null, null, null, $actionbar);
print_grade_page_head($courseid, 'report', 'user', false, false, false, true, null, null, $report->user, $actionbar);
if ($currentgroup && !groups_is_member($currentgroup, $userid)) {
echo $OUTPUT->notification(get_string('groupusernotmember', 'error'));
@ -198,12 +196,9 @@ if (has_capability('moodle/grade:viewall', $context)) {
// Students will see just their own report.
// Create a report instance.
$report = new gradereport_user\report\user($courseid, $gpr, $context, $userid ?? $USER->id);
$userheading = $gradesrenderer->user_heading($report->user, $courseid, false);
// Print the page.
print_grade_page_head($courseid, 'report', 'user');
echo $OUTPUT->heading($userheading);
print_grade_page_head($courseid, 'report', 'user', false, false, false, true, null, null, $report->user);
if ($report->fill_table()) {
echo $report->print_table(true);

View File

@ -57,7 +57,7 @@
{{{image}}}
</div>
<div class="d-flex ml-2">
<a class="h4 m-0" href="{{userprofileurl}}">{{name}}</a>
<h2><a class="h4 m-0" href="{{userprofileurl}}">{{name}}</a></h2>
</div>
<div class="d-inline-flex ml-4">
{{#buttons}}