You are here

public function FallbackController::getEntityFallbackCandidates in Entity Language Fallback 8

@todo: Consider using @cache.memory service for cache meta-data (8.6+).

Overrides FallbackControllerInterface::getEntityFallbackCandidates

File

src/FallbackController.php, line 57

Class

FallbackController

Namespace

Drupal\entity_language_fallback

Code

public function getEntityFallbackCandidates(ContentEntityInterface $entity, $language_code) {

  // Result of this can change by entity + bundle combination.
  $cid = "{$entity->getEntityType()->id()}:{$entity->bundle()}";
  if (isset($this->entityBundleCandidates[$cid])) {
    return $this->entityBundleCandidates[$cid];
  }

  // Generate if the value is missing.
  $candidates = [];
  if ($entity
    ->isTranslatable()) {
    $candidates[$language_code] = $language_code;
    foreach ($this
      ->getFallbackChain($language_code) as $fallback_langcode) {
      if (!(empty($fallback_langcode) || isset($candidates[$fallback_langcode]))) {
        $candidates[$fallback_langcode] = $fallback_langcode;
      }
    }
  }
  $this->entityBundleCandidates[$cid] = $candidates;
  return $candidates;
}