From e4f2074113e0c9d2e9d4927922edb26da231bf19 Mon Sep 17 00:00:00 2001 From: edysmp Date: Sat, 21 Jan 2017 12:05:57 +0300 Subject: [PATCH] Issue #2833546 by edysmp, juancasantito, heddn: Support drupal_field translatability. --- src/TwigExtension.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/TwigExtension.php b/src/TwigExtension.php index fd12cbb..8b37bcb 100644 --- a/src/TwigExtension.php +++ b/src/TwigExtension.php @@ -198,14 +198,19 @@ class TwigExtension extends \Twig_Extension { * The ID of the entity to render. * @param string $view_mode * (optional) The view mode that should be used to render the entity. + * @param string $langcode + * (optional) The langcode that should be used to render the entity. * * @return null|array * A render array for the field or NULL if the value does not exist. */ - public function drupalField($field_name, $entity_type, $id = NULL, $view_mode = 'default') { + public function drupalField($field_name, $entity_type, $id = NULL, $view_mode = 'default', $langcode = NULL) { $entity = $id ? $this->entityTypeManager->getStorage($entity_type)->load($id) : $this->routeMatch->getParameter($entity_type); + if ($langcode && $entity->hasTranslation($langcode)) { + $entity = $entity->getTranslation($langcode); + } if (isset($entity->{$field_name})) { return $entity->{$field_name}->view($view_mode); }