W3cubDocs

/Drupal 8

function hook_node_update_index

hook_node_update_index(\Drupal\node\NodeInterface $node)

Act on a node being indexed for searching.

This hook is invoked during search indexing, after loading, and after the result of rendering is added as $node->rendered to the node object.

Parameters

\Drupal\node\NodeInterface $node: The node being indexed.

Return value

string Additional node information to be indexed.

Related topics

Entity CRUD, editing, and view hooks
Hooks used in various entity operations.
Hooks
Define functions that alter the behavior of Drupal core.

File

core/modules/node/node.api.php, line 395
Hooks specific to the Node module.

Code

function hook_node_update_index(\Drupal\node\NodeInterface $node) {
  $text = '';
  $ratings = db_query('SELECT title, description FROM {my_ratings} WHERE nid = :nid', array(':nid' => $node->id()));
  foreach ($ratings as $rating) {
    $text .= '<h2>' . Html::escape($rating->title) . '</h2>' . Xss::filter($rating->description);
  }
  return $text;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!node!node.api.php/function/hook_node_update_index/8.1.x