You are here

function synonyms_search_synonym_reindex in Synonyms 8

Same name and namespace in other branches
  1. 2.0.x modules/synonyms_search/synonyms_search.module \synonyms_search_synonym_reindex()

Mark all search index dependent on a given synonym config for reindexing.

Parameters

\Drupal\synonyms\SynonymInterface $synonym: Synonym config whose dependent search index should be marked for reindexing.

3 calls to synonyms_search_synonym_reindex()
synonyms_search_synonym_delete in synonyms_search/synonyms_search.module
Implements hook_ENTITY_TYPE_delete().
synonyms_search_synonym_insert in synonyms_search/synonyms_search.module
Implements hook_ENTITY_TYPE_insert().
synonyms_search_synonym_update in synonyms_search/synonyms_search.module
Implements hook_ENTITY_TYPE_update().

File

synonyms_search/synonyms_search.module, line 66
Integrates Synonyms with core Search module.

Code

function synonyms_search_synonym_reindex(SynonymInterface $synonym) {
  if ($synonym
    ->get('behavior') == 'synonyms.behavior.search') {
    $entity_type = \Drupal::entityTypeManager()
      ->getDefinition($synonym
      ->getProviderPluginInstance()
      ->getPluginDefinition()['controlled_entity_type']);
    $bundle = $synonym
      ->getProviderPluginInstance()
      ->getPluginDefinition()['controlled_bundle'];
    $query = \Drupal::entityQuery($entity_type
      ->id());
    $query
      ->condition($entity_type
      ->getKey('bundle'), $bundle);
    $result = $query
      ->execute();
    \Drupal::service('synonyms.behavior.search')
      ->entityMarkForReindexMultiple(array_values($result), $entity_type
      ->id());
  }
}