Skip to content

Commit

Permalink
Merge pull request #1090 from City-of-Helsinki/UHF-8691
Browse files Browse the repository at this point in the history
UHF-8691: Remove alt-text manipulation when caption or photographer information is available
  • Loading branch information
teroelonen authored Oct 21, 2024
2 parents d8fbc3f + dc75efd commit 52d0f27
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,14 @@ function _hdbt_preprocess_image_caption(array &$variables, string $entity_type,
// Check for image and image caption availability.
if ($entity->hasField($image) && $entity->hasField($image_caption)) {
$caption_variable = str_replace('field_', '', $image_caption);
$alt = '';
$caption = '';

// If caption exists, set it as initial variable for the alt text and
// image caption.
// If caption exists, set it as initial variable for the image caption.
if (!$entity->{$image_caption}->isEmpty()) {
$alt = $caption = $entity->{$image_caption}->value;
$caption = $entity->{$image_caption}->value;
}

// Combine photographer field value with caption and alt text.
// Combine photographer field value with caption.
if (
$entity->{$image}->entity?->hasField('field_photographer') &&
!$entity->{$image}->entity->field_photographer->isEmpty()
Expand All @@ -347,7 +345,7 @@ function _hdbt_preprocess_image_caption(array &$variables, string $entity_type,
// for the caption and photographer. Otherwise, set only photographer as
// caption.
if (!empty($caption)) {
$alt = $caption = t(
$caption = t(
'@caption Photo: @photographer',
['@photographer' => $photographer, '@caption' => $caption],
['context' => 'Image caption and photographer']
Expand All @@ -364,16 +362,6 @@ function _hdbt_preprocess_image_caption(array &$variables, string $entity_type,

// Set image caption variable to render array for the templates.
$variables[$caption_variable] = $caption;

if (
!empty($alt) &&
$entity->{$image}->entity?->hasField('field_media_image') &&
!$entity->{$image}->entity->field_media_image->first()->isEmpty()
) {
// Set altered_alt_text variable based on modified alt text
// for the responsive image preprocesses.
$entity->{$image}->entity->field_media_image->first()->altered_alt_text = $alt;
}
}
}

Expand Down

0 comments on commit 52d0f27

Please sign in to comment.