From 896d5fd05a6947282760edc95e8462065023ceb1 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Mon, 21 Aug 2023 22:41:22 +0800 Subject: [PATCH] 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. --- lib/outputrenderers.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 59bfce5ce7d..cecc624bf9a 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -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) {