Skip to content

Commit

Permalink
Merge pull request #912 from City-of-Helsinki/UHF-X_get_original_alt
Browse files Browse the repository at this point in the history
UHF-X: Add original alt attribute to all images
  • Loading branch information
khalima authored Feb 27, 2024
2 parents 089d841 + b732d79 commit bd9aea9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,10 @@ function hdbt_preprocess_responsive_image_formatter(&$variables): void {

// Override alt text if alteration exists.
if (!empty($variables['item']->altered_alt_text)) {
// 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;
}

Expand Down

0 comments on commit bd9aea9

Please sign in to comment.