Browse Source

Make drupal_field() respect curent site language.

merge-requests/4/head 8.x-2.0-rc3
Chi 7 years ago
parent
commit
03d0c30e8e
  1. 6
      src/TwigExtension.php

6
src/TwigExtension.php

@ -4,6 +4,7 @@ namespace Drupal\twig_tweak;
use Drupal\Component\Uuid\Uuid; use Drupal\Component\Uuid\Uuid;
use Drupal\Core\Block\TitleBlockPluginInterface; use Drupal\Core\Block\TitleBlockPluginInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Link; use Drupal\Core\Link;
use Drupal\Core\Site\Settings; use Drupal\Core\Site\Settings;
use Drupal\Core\Url; use Drupal\Core\Url;
@ -188,9 +189,8 @@ class TwigExtension extends \Twig_Extension {
? \Drupal::entityTypeManager()->getStorage($entity_type)->load($id) ? \Drupal::entityTypeManager()->getStorage($entity_type)->load($id)
: \Drupal::routeMatch()->getParameter($entity_type); : \Drupal::routeMatch()->getParameter($entity_type);
if ($entity && (!$check_access || $entity->access('view'))) { if ($entity && (!$check_access || $entity->access('view'))) {
if ($langcode && $entity->hasTranslation($langcode)) { $entity = \Drupal::service('entity.repository')
$entity = $entity->getTranslation($langcode); ->getTranslationFromContext($entity, $langcode);
}
if (isset($entity->{$field_name})) { if (isset($entity->{$field_name})) {
return $entity->{$field_name}->view($view_mode); return $entity->{$field_name}->view($view_mode);
} }

Loading…
Cancel
Save