class NodeSearchHooks
Hook implementations for node entity operations.
Hierarchy
- class \Drupal\node\Hook\NodeSearchHooks
Expanded class hierarchy of NodeSearchHooks
File
-
core/
modules/ node/ src/ Hook/ NodeSearchHooks.php, line 13
Namespace
Drupal\node\HookView source
class NodeSearchHooks {
public function __construct(protected readonly ?SearchIndexInterface $searchIndex = NULL) {
}
/**
* Implements hook_node_update().
*/
public function nodeUpdate($node) : void {
$this->reindexNodeForSearch($node->id());
}
/**
* Implements hook_ENTITY_TYPE_insert() for comment entities.
*/
public function commentInsert($comment) : void {
// Reindex the node when comments are added.
if ($comment->getCommentedEntityTypeId() == 'node') {
$this->reindexNodeForSearch($comment->getCommentedEntityId());
}
}
/**
* Implements hook_ENTITY_TYPE_update() for comment entities.
*/
public function commentUpdate($comment) : void {
// Reindex the node when comments are changed.
if ($comment->getCommentedEntityTypeId() == 'node') {
$this->reindexNodeForSearch($comment->getCommentedEntityId());
}
}
/**
* Implements hook_ENTITY_TYPE_delete() for comment entities.
*/
public function commentDelete($comment) : void {
// Reindex the node when comments are deleted.
if ($comment->getCommentedEntityTypeId() == 'node') {
$this->reindexNodeForSearch($comment->getCommentedEntityId());
}
}
/**
* Reindex a node for search.
*
* @param string|int $nid
* The node ID to reindex.
*/
protected function reindexNodeForSearch(string|int $nid) : void {
// Reindex node context indexed by the node module search plugin.
$this->searchIndex?->markForReindex('node_search', (int) $nid);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
NodeSearchHooks::commentDelete | public | function | Implements hook_ENTITY_TYPE_delete() for comment entities. |
NodeSearchHooks::commentInsert | public | function | Implements hook_ENTITY_TYPE_insert() for comment entities. |
NodeSearchHooks::commentUpdate | public | function | Implements hook_ENTITY_TYPE_update() for comment entities. |
NodeSearchHooks::nodeUpdate | public | function | Implements hook_node_update(). |
NodeSearchHooks::reindexNodeForSearch | protected | function | Reindex a node for search. |
NodeSearchHooks::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.