You are here

public function FallbackController::getTranslations in Entity Language Fallback 8

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity:

Return value

[] Array of entity translations, including fallback content.

Overrides FallbackControllerInterface::getTranslations

File

src/FallbackController.php, line 112

Class

FallbackController

Namespace

Drupal\entity_language_fallback

Code

public function getTranslations(ContentEntityInterface $entity) {
  $translations = [];
  foreach ($this->languageManager
    ->getLanguages() as $langcode => $language) {
    if ($entity
      ->hasTranslation($langcode)) {
      $translations[$langcode] = $entity
        ->getTranslation($langcode);
    }
    elseif ($fallback = $this
      ->getTranslation($langcode, $entity)) {
      $translations[$langcode] = $fallback;
    }
  }
  return $translations;
}