function SearchNodeHooks::preDelete
Implements hook_entity_predelete().
Attributes
#[Hook('entity_predelete')]
File
-
core/
modules/ search/ modules/ search_node/ src/ Hook/ SearchNodeHooks.php, line 19
Class
- SearchNodeHooks
- Hooks for the Search Node module.
Namespace
Drupal\search_node\HookCode
public static function preDelete(EntityInterface $entity) : void {
// Ensure that all nodes deleted are removed from the search index.
if ($entity->getEntityTypeId() === 'node') {
if (\Drupal::hasService('search.index')) {
/** @var \Drupal\search\SearchIndexInterface $search_index */
$search_index = \Drupal::service('search.index');
$search_index->clear('node_search', $entity->id());
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.