1 nodeapi_example.module nodeapi_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/nodeapi_example/nodeapi_example.module, line 244
Module implementation for nodeapi_example module.

Code

function nodeapi_example_node_view($node, $build_mode = 'full') {
  if (config_get('nodeapi_example.settings', 'nodeapi_example_node_type_' . $node->type)) {
    // Make sure to set a rating, also for nodes saved previously and not yet
    // rated.
    $rating = isset($node->nodeapi_example_rating) ? $node->nodeapi_example_rating : 0;
    $node->content['nodeapi_example'] = array(
      '#markup' => theme('nodeapi_example_rating', array('rating' => $rating)),
      '#weight' => -1,
    );
  }
}