Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-8691: Remove alt-text manipulation when caption or photographer information is available #1090

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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