1 node.module node_view(Node $node, $view_mode = 'full', $langcode = NULL)

Generates an array for rendering the given node.

Parameters

Node $node: A node entity.

$view_mode: (optional) Display mode, e.g. 'full' or 'teaser'. Defaults to 'full'.

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

Return value

An array as expected by backdrop_render().:

File

core/modules/node/node.module, line 1096
The core module that allows content to be submitted to the site.

Code

function node_view(Node $node, $view_mode = 'full', $langcode = NULL) {
  if (!isset($langcode)) {
    $langcode = $GLOBALS['language_content']->langcode;
  }

  // Populate $node->content with a render() array.
  node_build_content($node, $view_mode, $langcode);

  $build = $node->content;
  // We don't need duplicate rendering info in node->content.
  unset($node->content);

  $build += array(
    '#theme' => 'node__' . $node->type . '__' . $view_mode,
    '#node' => $node,
    '#view_mode' => $view_mode,
    '#langcode' => $langcode,
  );

  // Add contextual links for this node, except when the node is already being
  // displayed on its own page. Modules may alter this behavior (for example,
  // to restrict contextual links to certain display modes) by implementing
  // hook_node_view_alter().
  if (!empty($node->nid) && !($view_mode == 'full' && node_is_page($node))) {
    $build['#contextual_links']['node'] = array('node', array($node->nid));
  }

  // Allow modules to modify the structured node.
  $type = 'node';
  backdrop_alter(array('node_view', 'entity_view'), $build, $type);

  return $build;
}