You are here

public function ContentEntityFallback::getPartialItemIds in Entity Language Fallback 8

Overrides ContentEntity::getPartialItemIds

File

src/Plugin/search_api/datasource/ContentEntityFallback.php, line 101

Class

ContentEntityFallback
Represents a datasource which exposes the content entities.

Namespace

Drupal\entity_language_fallback\Plugin\search_api\datasource

Code

public function getPartialItemIds($page = NULL, array $bundles = NULL, array $languages = NULL) {
  $parent_items = parent::getPartialItemIds($page, $bundles, $languages);
  if (empty($parent_items)) {
    return $parent_items;
  }
  $entity_ids = [];
  foreach ($parent_items as $parent_item) {
    list($id, ) = Utility::splitPropertyPath($parent_item);
    $entity_ids[$id] = 1;
  }

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  foreach ($this
    ->getEntityStorage()
    ->loadMultiple(array_keys($entity_ids)) as $entity_id => $entity) {
    foreach ($this->languages as $langcode => $language) {
      if ($entity
        ->hasTranslation($langcode)) {
        $item_ids[] = "{$entity_id}:{$langcode}";
      }
      else {
        $fallback_found = FALSE;
        foreach ($this->fallback_chain[$langcode] as $candidate) {
          if ($entity
            ->hasTranslation($candidate)) {
            $fallback_found = TRUE;
            break;
          }
        }
        if ($fallback_found) {
          $item_ids[] = "{$entity_id}:{$langcode}";
        }
      }
    }
  }
  return $item_ids;
}