MDL-79059 core: Use full name as alt text for user picture links

When the user picture is being rendered as a link but the user's full
name is not being included in the link and the alt text turns out to be
empty, we could end up with a link without a discernible text. This is
an accessibility issue that will affect screen reader users. If this is
the case, use the full name as the user picture's alt text.
This commit is contained in:
Jun Pataleta 2023-08-21 22:41:22 +08:00
parent f9c46d0026
commit 896d5fd05a
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7

View File

@ -2656,10 +2656,18 @@ class core_renderer extends renderer_base {
$alt = '';
if ($userpicture->alttext) {
if (!empty($user->imagealt)) {
$alt = $user->imagealt;
$alt = trim($user->imagealt);
}
}
// If the user picture is being rendered as a link but without the full name, an empty alt text for the user picture
// would mean that the link displayed will not have any discernible text. This becomes an accessibility issue,
// especially to screen reader users. Use the user's full name by default for the user picture's alt-text if this is
// the case.
if ($userpicture->link && !$userpicture->includefullname && empty($alt)) {
$alt = fullname($user);
}
if (empty($userpicture->size)) {
$size = 35;
} else if ($userpicture->size === true or $userpicture->size == 1) {