From 728f4d40d56e40a2b328ff14c45d0b0c534bd853 Mon Sep 17 00:00:00 2001 From: mariacha Date: Tue, 1 Oct 2024 19:20:49 -0700 Subject: [PATCH] Automatically translate to the right language. --- modules/wri_common/wri_common.module | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/wri_common/wri_common.module b/modules/wri_common/wri_common.module index 04b0b66e6..cb8016d2b 100644 --- a/modules/wri_common/wri_common.module +++ b/modules/wri_common/wri_common.module @@ -392,7 +392,11 @@ function wri_common_get_node_topic_children(Node $node) { function _wri_common_format_list(array $terms) { $list = ''; if ($terms) { + $lang_code = \Drupal::service('language_manager')->getCurrentLanguage()->getId(); foreach ($terms as $term) { + if ($term->hasTranslation($lang_code)) { + $term = $term->getTranslation($lang_code); + } $published = $term->isPublished(); if ($published) { $term_url = $term->toUrl(); @@ -446,6 +450,10 @@ function _wri_common_format_list(array $terms) { * A string representing the entity with or without a link. */ function wri_common_link_or_text(EntityInterface $entity, ?NodeInterface $node = NULL) { + $lang_code = \Drupal::service('language_manager')->getCurrentLanguage()->getId(); + if ($entity->hasTranslation($lang_code)) { + $entity = $entity->getTranslation($lang_code); + } $link = ''; if (isset($entity)) { if ($entity->isPublished()) {