You are here

public function EntityTranslationRenderTrait::getEntityTranslation in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.php \Drupal\views\Entity\Render\EntityTranslationRenderTrait::getEntityTranslation()

Returns the entity translation matching the configured row language.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object the field value being processed is attached to.

\Drupal\views\ResultRow $row: The result row the field value being processed belongs to.

Return value

\Drupal\Core\Entity\FieldableEntityInterface The entity translation object for the specified row.

3 calls to EntityTranslationRenderTrait::getEntityTranslation()
BulkForm::viewsForm in core/modules/system/src/Plugin/views/field/BulkForm.php
Form constructor for the bulk form.
EntityFieldRenderer::buildFields in core/modules/views/src/Entity/Render/EntityFieldRenderer.php
Builds the render arrays for all fields of all result rows.
EntityOperations::render in core/modules/views/src/Plugin/views/field/EntityOperations.php
Renders the field.

File

core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.php, line 74
Contains \Drupal\views\Entity\Render\EntityTranslationRenderTrait.

Class

EntityTranslationRenderTrait
Trait used to instantiate the view's entity translation renderer.

Namespace

Drupal\views\Entity\Render

Code

public function getEntityTranslation(EntityInterface $entity, ResultRow $row) {

  // We assume the same language should be used for all entity fields
  // belonging to a single row, even if they are attached to different entity
  // types. Below we apply language fallback to ensure a valid value is always
  // picked.
  $translation = $entity;
  if ($entity instanceof TranslatableInterface && count($entity
    ->getTranslationLanguages()) > 1) {
    $langcode = $this
      ->getEntityTranslationRenderer()
      ->getLangcode($row);
    $translation = $this
      ->getEntityManager()
      ->getTranslationFromContext($entity, $langcode);
  }
  return $translation;
}