123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- /**
- * @file
- * Integrates Synonyms with core Search module.
- */
- /**
- * Implements hook_entity_view().
- */
- function synonyms_search_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
- \Drupal::service('synonyms.behavior.search')->entityView($build, $entity, $display, $view_mode);
- }
- /**
- * Implements hook_entity_update().
- */
- function synonyms_search_entity_update(Drupal\Core\Entity\EntityInterface $entity) {
- if ($entity instanceof \Drupal\Core\Entity\ContentEntityInterface) {
- \Drupal::service('synonyms.behavior.search')->entityMarkForReindex($entity);
- }
- }
- /**
- * Implements hook_entity_delete().
- */
- function synonyms_search_entity_delete(Drupal\Core\Entity\EntityInterface $entity) {
- if ($entity instanceof \Drupal\Core\Entity\ContentEntityInterface) {
- \Drupal::service('synonyms.behavior.search')->entityMarkForReindex($entity);
- }
- }
- /**
- * Implements hook_ENTITY_TYPE_insert().
- */
- function synonyms_search_synonym_insert(Drupal\Core\Entity\EntityInterface $entity) {
- synonyms_search_synonym_reindex($entity);
- }
- /**
- * Implements hook_ENTITY_TYPE_update().
- */
- function synonyms_search_synonym_update(Drupal\Core\Entity\EntityInterface $entity) {
- synonyms_search_synonym_reindex($entity);
- }
- /**
- * Implements hook_ENTITY_TYPE_delete().
- */
- function synonyms_search_synonym_delete(Drupal\Core\Entity\EntityInterface $entity) {
- synonyms_search_synonym_reindex($entity);
- }
- /**
- * Mark all search index dependent on a given synonym config for reindexing.
- *
- * @param \Drupal\synonyms\SynonymInterface $synonym
- * Synonym config whose dependent search index should be marked for reindexing
- */
- function synonyms_search_synonym_reindex(\Drupal\synonyms\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());
- }
- }
|