From 03d0c30e8e36e38af6db2aa59f80a4280bd7d498 Mon Sep 17 00:00:00 2001 From: Chi Date: Wed, 7 Mar 2018 11:49:17 +0500 Subject: [PATCH] Make drupal_field() respect curent site language. --- src/TwigExtension.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TwigExtension.php b/src/TwigExtension.php index 787e955..730c6ff 100644 --- a/src/TwigExtension.php +++ b/src/TwigExtension.php @@ -4,6 +4,7 @@ namespace Drupal\twig_tweak; use Drupal\Component\Uuid\Uuid; use Drupal\Core\Block\TitleBlockPluginInterface; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Link; use Drupal\Core\Site\Settings; use Drupal\Core\Url; @@ -188,9 +189,8 @@ class TwigExtension extends \Twig_Extension { ? \Drupal::entityTypeManager()->getStorage($entity_type)->load($id) : \Drupal::routeMatch()->getParameter($entity_type); if ($entity && (!$check_access || $entity->access('view'))) { - if ($langcode && $entity->hasTranslation($langcode)) { - $entity = $entity->getTranslation($langcode); - } + $entity = \Drupal::service('entity.repository') + ->getTranslationFromContext($entity, $langcode); if (isset($entity->{$field_name})) { return $entity->{$field_name}->view($view_mode); }