function hook_node_search_result
Same name in other branches
- 7.x modules/node/node.api.php \hook_node_search_result()
- 9 core/modules/node/node.api.php \hook_node_search_result()
- 8.9.x core/modules/node/node.api.php \hook_node_search_result()
- 11.x core/modules/node/node.api.php \hook_node_search_result()
Act on a node being displayed as a search result.
This hook is invoked from the node search plugin during search execution, after loading and rendering the node.
Parameters
\Drupal\node\NodeInterface $node: The node being displayed in a search result.
Return value
array Extra information to be displayed with search result. This information should be presented as an associative array. It will be concatenated with the post information (last updated, author) in the default search result theming.
See also
template_preprocess_search_result()
Related topics
1 function implements hook_node_search_result()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- comment_node_search_result in core/
modules/ comment/ comment.module - Implements hook_node_search_result().
1 invocation of hook_node_search_result()
- NodeSearch::prepareResults in core/
modules/ node/ src/ Plugin/ Search/ NodeSearch.php - Prepares search results for rendering.
File
-
core/
modules/ node/ node.api.php, line 303
Code
function hook_node_search_result(\Drupal\node\NodeInterface $node) {
$rating = \Drupal::database()->query('SELECT SUM([points]) FROM {my_rating} WHERE [nid] = :nid', [
'nid' => $node->id(),
])
->fetchField();
return [
'rating' => \Drupal::translation()->formatPlural($rating, '1 point', '@count points'),
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.