node_build_content

Versions
5 – 6
node_build_content($node, $teaser = FALSE, $page = FALSE)
7
node_build_content(stdClass $node, $build_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 $build_mode parameter.

Drupal core defines the following build 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 build modes, or use existing build modes in additional contexts.

Parameters

$node A node object.

$build_mode Build mode, e.g. 'full', 'teaser'...

▾ 1 function calls node_build_content()

node_build in modules/node/node.module
Generate an array for rendering the given node.

Code

modules/node/node.module, line 1184

<?php
function node_build_content(stdClass $node, $build_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', $build_mode);
  }

  // Build fields content.
  // @todo field_attach_prepare_view() is only invoked by node_build_multiple(),
  //   all other entities invoke it _here_.
  //field_attach_prepare_view('node', array($node->nid => $node), $build_mode);
  $node->content += field_attach_view('node', $node, $build_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 ($build_mode == 'teaser') {
    $links['node_readmore'] = array(
      'title' => t('Read more'),
      'href' => 'node/' . $node->nid,
      'attributes' => array('rel' => 'tag', 'title' => strip_tags($node->title[FIELD_LANGUAGE_NONE][0]['value']))
    );
  }
  $node->content['links']['node'] = array(
    '#theme' => 'links',
    '#links' => $links,
    '#attributes' => array('class' => array('links', 'inline')),
  );

  // Allow modules to make their own additions to the node.
  module_invoke_all('node_view', $node, $build_mode);
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.