You are here

public static function ContentEntityFallback::getIndexesForEntity in Entity Language Fallback 8

Overrides ContentEntity::getIndexesForEntity

3 calls to ContentEntityFallback::getIndexesForEntity()
entity_language_fallback_entity_delete in ./entity_language_fallback.module
Implements hook_entity_delete().
entity_language_fallback_entity_insert in ./entity_language_fallback.module
Implements hook_entity_insert().
entity_language_fallback_entity_update in ./entity_language_fallback.module
Implements hook_entity_update().

File

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

Class

ContentEntityFallback
Represents a datasource which exposes the content entities.

Namespace

Drupal\entity_language_fallback\Plugin\search_api\datasource

Code

public static function getIndexesForEntity(ContentEntityInterface $entity) {
  $datasource_id = 'entity_language_fallback:' . $entity
    ->getEntityTypeId();
  $entity_bundle = $entity
    ->bundle();
  $has_bundles = $entity
    ->getEntityType()
    ->hasKey('bundle');
  $indexes = Index::loadMultiple();
  foreach ($indexes as $index_id => $index) {

    // Filter our indexes that don't contain the datasource in question.
    if (!$index
      ->isValidDatasource($datasource_id)) {
      unset($indexes[$index_id]);
    }
    elseif ($has_bundles) {

      // If the entity type supports bundles, we also have to filter out
      // indexes that exclude the entity's bundle.
      $config = $index
        ->getDatasource($datasource_id)
        ->getConfiguration();
      $default = !empty($config['bundles']['default']);
      $bundle_set = in_array($entity_bundle, $config['bundles']['selected']);
      if ($default == $bundle_set) {
        unset($indexes[$index_id]);
      }
    }
  }
  return $indexes;
}