function EntityRepositoryInterface::getTranslationFromContext

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityRepositoryInterface.php \Drupal\Core\Entity\EntityRepositoryInterface::getTranslationFromContext()
  2. 8.9.x core/lib/Drupal/Core/Entity/EntityRepositoryInterface.php \Drupal\Core\Entity\EntityRepositoryInterface::getTranslationFromContext()
  3. 10 core/lib/Drupal/Core/Entity/EntityRepositoryInterface.php \Drupal\Core\Entity\EntityRepositoryInterface::getTranslationFromContext()

Gets the entity translation to be used in the given context.

This will check whether a translation for the desired language is available and if not, it will fall back to the most appropriate translation based on the provided context.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity whose translation will be returned.

string $langcode: (optional) The language of the current context. Defaults to the current content language.

array $context: (optional) An associative array of arbitrary data that can be useful to determine the proper fallback sequence. See \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates().

Return value

\Drupal\Core\Entity\EntityInterface|null An entity object for the translated data, or NULL if the requested translation is missing, forbidden, or unavailable.

See also

\Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates()

1 method overrides EntityRepositoryInterface::getTranslationFromContext()
EntityRepository::getTranslationFromContext in core/lib/Drupal/Core/Entity/EntityRepository.php
Gets the entity translation to be used in the given context.

File

core/lib/Drupal/Core/Entity/EntityRepositoryInterface.php, line 80

Class

EntityRepositoryInterface
Provides an interface for an entity repository.

Namespace

Drupal\Core\Entity

Code

public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = []);

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.