Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function hook_view

Display a node.

This is a node-type-specific hook, which is invoked only for the node type being affected. See Node API hooks for more information.

Use hook_node_view() to respond to node view of all node types.

This hook is invoked during node viewing after the node is fully loaded, so that the node type module can define a custom method for display, or add to the default display.

Parameters

$node: The node to be displayed, as returned by node_load().

$view_mode: View mode, e.g. 'full', 'teaser', ...

$langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.

Return value

The passed $node parameter should be modified as necessary and returned so it can be properly presented. Nodes are prepared for display by assembling a structured array, formatted as in the Form API, in $node->content. As with Form API arrays, the #weight property can be used to control the relative positions of added elements. After this hook is invoked, node_view() calls field_attach_view() to add field views to $node->content, and then invokes hook_node_view() and hook_node_view_alter(), so if you want to affect the final view of the node, you might consider implementing one of these hooks instead.

Related topics

Node API Hooks
Functions to define and modify content types.
Hooks
Allow modules to interact with the Drupal core.
61 functions implement hook_view()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

aggregator_block_view in modules/aggregator/aggregator.module
Implements hook_block_view().
aggregator_view in modules/aggregator/aggregator.admin.inc
Displays the aggregator administration page.
block_block_view in modules/block/block.module
Implements hook_block_view().
block_test_block_view in modules/block/tests/block_test.module
Implements hook_block_view().
blog_block_view in modules/blog/blog.module
Implements hook_block_view().

... See full list

File

modules/node/node.api.php, line 1314

Code

function hook_view ($node, $view_mode, $langcode = NULL) {
 if ($view_mode == 'full' && node_is_page ($node)) {
 $breadcrumb = array();
 $breadcrumb[] = l (t ('Home'), NULL);
 $breadcrumb[] = l (t ('Example'), 'example');
 $breadcrumb[] = l ($node->field1 , 'example/' . $node->field1 );
 drupal_set_breadcrumb ($breadcrumb);
 }
 $node->content ['myfield'] = array(
 '#markup' => theme ('mymodule_myfield', $node->myfield),
 '#weight' => 1,
 );
 return $node;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.