function hook_node_view

Act on a node that is being assembled before rendering.

The module may add elements to $node->content prior to rendering. This hook will be called after hook_view(). The structure of $node->content is a renderable array as expected by drupal_render().

When $view_mode is 'rss', modules can also add extra RSS elements and namespaces to $node->rss_elements and $node->rss_namespaces respectively for the RSS item generated for this node. For details on how this is used, see node_feed().

Parameters

$node: The node that is being assembled for rendering.

$view_mode: The $view_mode parameter from node_view().

$langcode: The language code used for rendering.

See also

blog_node_view()

forum_node_view()

comment_node_view()

hook_entity_view()

Related topics

11 functions implement hook_node_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.

BlockContentThemeSuggestionsTestHooks::nodeView in core/modules/block_content/tests/modules/block_content_theme_suggestions_test/src/Hook/BlockContentThemeSuggestionsTestHooks.php
Implements hook_node_view().
blog_node_view in modules/blog/blog.module
Implements hook_node_view().
book_node_view in modules/book/book.module
Implements hook_node_view().
comment_node_view in modules/comment/comment.module
Implements hook_node_view().
forum_node_view in modules/forum/forum.module
Implements hook_node_view().

... See full list

1 invocation of hook_node_view()
node_build_content in modules/node/node.module
Builds a structured array representing the node's content.

File

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

Code

function hook_node_view($node, $view_mode, $langcode) {
    $node->content['my_additional_field'] = array(
        '#markup' => $additional_field,
        '#weight' => 10,
        '#theme' => 'mymodule_my_additional_field',
    );
}

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