1 node_hooks_example.module | node_hooks_example_node_view($node, $build_mode = 'full') |
Implements hook_node_view().
This is a typical implementation that simply runs the node text through the output filters.
Finally, we need to take care of displaying our rating when the node is viewed. This operation is called after the node has already been prepared into HTML and filtered as necessary, so we know we are dealing with an HTML teaser and body. We will inject our additional information at the front of the node copy.
Using node API 'hook_node_view' is more appropriate than using a filter here, because filters transform user-supplied content, whereas we are extending it with additional information.
Related topics
File
- modules/
examples/ node_hooks_example/ node_hooks_example.module, line 225 - Hook implementations for the Node Hooks Example module.
Code
function node_hooks_example_node_view($node, $build_mode = 'full') {
if (config_get('node_hooks_example.settings', 'node_hooks_example_node_type_' . $node->type)) {
// Make sure to set a rating, also for nodes saved previously and not yet
// rated.
$rating = isset($node->node_hooks_example_rating) ? $node->node_hooks_example_rating : 0;
$node->content['node_hooks_example'] = array(
'#markup' => theme('node_hooks_example_rating', array('rating' => $rating)),
'#weight' => -1,
);
}
}