From 56cc0a44ae4115fd1c1f517f1a2cd1785962f7ae Mon Sep 17 00:00:00 2001 From: Mikko Tapionlinna Date: Tue, 27 Feb 2024 15:48:40 +0200 Subject: [PATCH 1/2] UHF-X: Add original alt attribute to all images --- hdbt.theme | 1 + 1 file changed, 1 insertion(+) diff --git a/hdbt.theme b/hdbt.theme index e37cdf0ea..9e2b06919 100644 --- a/hdbt.theme +++ b/hdbt.theme @@ -1165,6 +1165,7 @@ function hdbt_preprocess_responsive_image_formatter(&$variables): void { // Override alt text if alteration exists. if (!empty($variables['item']->altered_alt_text)) { + $variables['responsive_image']['#attributes']['data-original-alt'] = $variables['responsive_image']['#attributes']['alt']; $variables['responsive_image']['#attributes']['alt'] = $variables['item']->altered_alt_text; } From b732d79d151d0649141824c30bccf997fcf4039f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Tue, 27 Feb 2024 16:27:16 +0200 Subject: [PATCH 2/2] Check for the existence of alt attribute before applying it to data-attribute. --- hdbt.theme | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hdbt.theme b/hdbt.theme index 9e2b06919..6e1e00823 100644 --- a/hdbt.theme +++ b/hdbt.theme @@ -1165,7 +1165,10 @@ function hdbt_preprocess_responsive_image_formatter(&$variables): void { // Override alt text if alteration exists. if (!empty($variables['item']->altered_alt_text)) { - $variables['responsive_image']['#attributes']['data-original-alt'] = $variables['responsive_image']['#attributes']['alt']; + // Set original alt text to data attribute. + if (isset($variables['responsive_image']['#attributes']['alt'])) { + $variables['responsive_image']['#attributes']['data-original-alt'] = $variables['responsive_image']['#attributes']['alt']; + } $variables['responsive_image']['#attributes']['alt'] = $variables['item']->altered_alt_text; }