function SearchNodeHooks::nodeUpdate

Implements hook_ENTITY_TYPE_update().

Attributes

#[Hook('node_update')]

File

core/modules/search/modules/search_node/src/Hook/SearchNodeHooks.php, line 42

Class

SearchNodeHooks
Hooks for the Search Node module.

Namespace

Drupal\search_node\Hook

Code

public function nodeUpdate(NodeInterface $node) : void {
  // Remove deleted translations from the search index.
  $node_original = $node->getOriginal();
  $removed_translations = array_diff_key($node_original->getTranslationLanguages(), $node->getTranslationLanguages());
  foreach (array_keys($removed_translations) as $langcode) {
    \Drupal::service('search.index')->clear('node_search', $node_original->id(), $langcode);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.