Skip to content

Commit

Permalink
MDL-79045 grade: Don't enclose grade user_heading in $OUTPUT->heading()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
junpataleta committed Aug 31, 2023
1 parent e54c280 commit c2f25b7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
7 changes: 5 additions & 2 deletions grade/lib.php
Expand Up @@ -889,7 +889,7 @@ public function __construct($id, $link, $string, $parent=null) {
function print_grade_page_head(int $courseid, string $active_type, ?string $active_plugin = null, $heading = false,
bool $return = false, $buttons = false, bool $shownavigation = true, ?string $headerhelpidentifier = null,
?string $headerhelpcomponent = null, ?stdClass $user = null, ?action_bar $actionbar = null, $showtitle = true) {
global $CFG, $OUTPUT, $PAGE;
global $CFG, $OUTPUT, $PAGE, $USER;

// Put a warning on all gradebook pages if the course has modules currently scheduled for background deletion.
require_once($CFG->dirroot . '/course/lib.php');
Expand Down Expand Up @@ -974,7 +974,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);
}
Expand Down
11 changes: 3 additions & 8 deletions grade/report/user/index.php
Expand Up @@ -160,7 +160,7 @@
$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);
Expand All @@ -174,9 +174,7 @@
$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'));
Expand All @@ -193,12 +191,9 @@
// 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);
Expand Down
2 changes: 1 addition & 1 deletion grade/templates/user_heading.mustache
Expand Up @@ -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}}
Expand Down

0 comments on commit c2f25b7

Please sign in to comment.