node_build_content

Versions
mediamosa-21
node_build_content($node, $view_mode = 'full')

Builds a structured array representing the node's content.

The content built for the node (field values, comments, file attachments or other node components) will vary depending on the $view_mode parameter.

Drupal core defines the following view modes for nodes, with the following default use cases:

  • full (default): node is being displayed on its own page (node/123)
  • teaser: node is being displayed on the default home page listing, on taxonomy listing pages, or on blog listing pages.
  • rss: node displayed in an RSS feed.

If search.module is enabled:

  • search_index: node is being indexed for search.
  • search_result: node is being displayed as a search result.

If book.module is enabled:

  • print: node is being displayed in print-friendly mode.

Contributed modules might define additional view modes, or use existing view modes in additional contexts.

Parameters

$node A node object.

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

▾ 3 functions call node_build_content()

hook_search_execute in modules/search/search.api.php
Execute a search for a set of key words.
hook_update_index in modules/search/search.api.php
Update the search index for this module.
node_view in modules/node/node.module
Generate an array for rendering the given node.

Code

modules/node/node.module, line 1250

<?php
function node_build_content($node, $view_mode = 'full') {
  // Remove previously built content, if exists.
  $node->content = array();

  // The 'view' hook can be implemented to overwrite the default function
  // to display nodes.
  if (node_hook($node, 'view')) {
    $node = node_invoke($node, 'view', $view_mode);
  }

  // Build fields content.
  // In case of a multiple view, node_view_multiple() already ran the
  // 'prepare_view' step. An internal flag prevents the operation from running
  // twice.
  field_attach_prepare_view('node', array($node->nid => $node), $view_mode);
  entity_prepare_view('node', array($node->nid => $node));
  $node->content += field_attach_view('node', $node, $view_mode);

  // Always display a read more link on teasers because we have no way
  // to know when a teaser view is different than a full view.
  $links = array();
  if ($view_mode == 'teaser') {
    $links['node_readmore'] = array(
      'title' => t('Read more'),
      'href' => 'node/' . $node->nid,
      'attributes' => array('rel' => 'tag', 'title' => strip_tags($node->title))
    );
  }
  $node->content['links']['node'] = array(
    '#theme' => 'links__node',
    '#links' => $links,
    '#attributes' => array('class' => array('links', 'inline')),
  );

  // Allow modules to make their own additions to the node.
  module_invoke_all('node_view', $node, $view_mode);
}
?>