You are here

function synonyms_search_synonym_reindex in Synonyms 2.0.x

Same name and namespace in other branches
  1. 8 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 modules/synonyms_search/synonyms_search.module
Implements hook_ENTITY_TYPE_delete().
synonyms_search_synonym_insert in modules/synonyms_search/synonyms_search.module
Implements hook_ENTITY_TYPE_insert().
synonyms_search_synonym_update in modules/synonyms_search/synonyms_search.module
Implements hook_ENTITY_TYPE_update().

File

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

Code

function synonyms_search_synonym_reindex(SynonymInterface $synonym) {
  $entity_type = \Drupal::entityTypeManager()
    ->getDefinition($synonym
    ->getProviderPluginInstance()
    ->getPluginDefinition()['controlled_entity_type']);
  if ($entity_type
    ->id() == 'user' || $entity_type
    ->hasKey('label')) {
    $bundle = $synonym
      ->getProviderPluginInstance()
      ->getPluginDefinition()['controlled_bundle'];
    $query = \Drupal::entityQuery($entity_type
      ->id());

    // User entity type does not declare its label, while it does have one.
    $label_column = $entity_type
      ->id() == 'user' ? 'name' : $entity_type
      ->getKey('label');
    $query
      ->condition($label_column, $bundle);
    $result = $query
      ->execute();
    \Drupal::service('synonyms.behavior.search')
      ->entityMarkForReindexMultiple(array_values($result), $entity_type
      ->id());
  }
}