You are here

public function FallbackController::getTranslation in Entity Language Fallback 8

Parameters

string $lang_code: Language code

\Drupal\Core\Entity\ContentEntityInterface $entity: Entity

Return value

mixed Fallback entity translation, or FALSE if nothing was found.

Overrides FallbackControllerInterface::getTranslation

1 call to FallbackController::getTranslation()
FallbackController::getTranslations in src/FallbackController.php

File

src/FallbackController.php, line 84

Class

FallbackController

Namespace

Drupal\entity_language_fallback

Code

public function getTranslation($lang_code, ContentEntityInterface $entity) {
  $this
    ->ensureFallbackChain($lang_code);
  foreach ($this->fallback_chain[$lang_code] as $candidate) {
    if ($entity
      ->hasTranslation($candidate)) {
      return $entity
        ->getTranslation($candidate);
    }
  }
  return FALSE;
}