From 69c0cd6b370891c276aa513f996c02bf35ad3cf3 Mon Sep 17 00:00:00 2001 From: Sakthi Shanmuga Sundaram M <62943-sakthi_dev@users.noreply.drupalcode.org> Date: Mon, 24 Jul 2023 14:37:38 +0000 Subject: [PATCH] Issue#3241175: Resolve translation issue. --- src/UrlExtractor.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/UrlExtractor.php b/src/UrlExtractor.php index 4fd8b35..ef5feba 100644 --- a/src/UrlExtractor.php +++ b/src/UrlExtractor.php @@ -72,11 +72,17 @@ class UrlExtractor { elseif ($input instanceof EntityReferenceItem) { $entity = $input->entity; } + + // Get the current Language Code. + $languageManager = \Drupal::languageManager(); + $currentLanguage = $languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT); + $languageCode = $currentLanguage->getId(); + // Drupal does not clean up references to deleted entities. So that the // entity property might be empty while the field item might not. // @see https://www.drupal.org/project/drupal/issues/2723323 return $entity instanceof ContentEntityInterface ? - $this->getUrlFromEntity($entity, $relative) : NULL; + $this->getUrlFromEntity($entity->hasTranslation($langcode) ? $entity->getTranslation($langcode) : $entity , $relative) : NULL; } /**