From 24cdc1fd949181703aeb2d7ab3b1b2dfb4c51f43 Mon Sep 17 00:00:00 2001 From: Deepak Mishra Date: Wed, 5 Mar 2025 12:56:26 +0530 Subject: [PATCH] fix mapped alt text issue. --- src/EmbedCodeFactory.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/EmbedCodeFactory.php b/src/EmbedCodeFactory.php index f3a60f1c..359c8bd1 100644 --- a/src/EmbedCodeFactory.php +++ b/src/EmbedCodeFactory.php @@ -2,6 +2,7 @@ namespace Drupal\acquia_dam; +use Drupal\acquia_dam\Entity\ImageAltTextField; use Drupal\acquia_dam\Entity\MediaSourceField; use Drupal\acquia_dam\Plugin\Field\FieldType\AssetItem; use Drupal\Core\Link; @@ -128,10 +129,10 @@ final class EmbedCodeFactory implements TrustedCallbackInterface { $asset_field = $media->get(MediaSourceField::SOURCE_FIELD_NAME)->first(); assert($asset_field instanceof AssetItem); - // @todo fetch alt text from asset metadata for a proper value. - // $media->getFieldDefinition(ImageAltTextField::IMAGE_ALT_TEXT_FIELD_NAME) - // $media->get(ImageAltTextField::IMAGE_ALT_TEXT_FIELD_NAME)->first() - $alt_text = $media->label(); + // Fetch alt text from the media entity, fallback to media label if not available. + $alt_text = $media->hasField(ImageAltTextField::IMAGE_ALT_TEXT_FIELD_NAME) + ? $media->get(ImageAltTextField::IMAGE_ALT_TEXT_FIELD_NAME)->value ?? $media->label() + : $media->label(); // Providing the embed code of the thumbnail image is independent from the // media type. -- GitLab