public static function TwigTweakExtension::entityTranslation in Twig Tweak 3.1.x
Same name and namespace in other branches
- 3.x src/TwigTweakExtension.php \Drupal\twig_tweak\TwigTweakExtension::entityTranslation()
Returns the translation for the given entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity to get the translation from.
string $langcode: (optional) For which language the translation should be looked for, defaults to the current language context.
Return value
\Drupal\Core\Entity\EntityInterface The appropriate translation for the given language context.
File
- src/
TwigTweakExtension.php, line 639
Class
- TwigTweakExtension
- Twig extension with some useful functions and filters.
Namespace
Drupal\twig_tweakCode
public static function entityTranslation(EntityInterface $entity, string $langcode = NULL) : EntityInterface {
return \Drupal::service('entity.repository')
->getTranslationFromContext($entity, $langcode);
}