function EntityTranslationRenderTrait::getEntityTranslationByRelationship
Same name in other branches
- 11.x core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.php \Drupal\views\Entity\Render\EntityTranslationRenderTrait::getEntityTranslationByRelationship()
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.
string $relationship: The relationship to be used, or 'none' by default.
Return value
\Drupal\Core\Entity\EntityInterface The entity translation object for the specified row.
7 calls to EntityTranslationRenderTrait::getEntityTranslationByRelationship()
- BulkForm::viewsForm in core/
modules/ views/ src/ Plugin/ views/ field/ BulkForm.php - Form constructor for the bulk form.
- DataEntityRow::render in core/
modules/ rest/ src/ Plugin/ views/ row/ DataEntityRow.php - Renders a row object.
- EntityFieldRenderer::buildFields in core/
modules/ views/ src/ Entity/ Render/ EntityFieldRenderer.php - Builds the render arrays for all fields of all result rows.
- EntityLink::getUrlInfo in core/
modules/ views/ src/ Plugin/ views/ field/ EntityLink.php - Returns the URI elements of the link.
- 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 92
Class
- EntityTranslationRenderTrait
- Trait used to instantiate the view's entity translation renderer.
Namespace
Drupal\views\Entity\RenderCode
public function getEntityTranslationByRelationship(EntityInterface $entity, ResultRow $row, string $relationship = 'none') : EntityInterface {
// 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.
if ($entity instanceof TranslatableInterface && count($entity->getTranslationLanguages()) > 1) {
$langcode = $this->getEntityTranslationRenderer()
->getLangcodeByRelationship($row, $relationship);
$translation = $this->getEntityRepository()
->getTranslationFromContext($entity, $langcode);
}
return $translation ?? $entity;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.