1 node.module node_view_multiple($nodes, $view_mode = 'teaser', $weight = 0, $langcode = NULL)

Constructs a backdrop_render() style array from an array of loaded nodes.

Parameters

$nodes: An array of nodes as returned by node_load_multiple().

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

$weight: (optional) Integer representing the weight of the first node in the list.

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

Return value

An array in the format expected by backdrop_render().:

File

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

Code

function node_view_multiple($nodes, $view_mode = 'teaser', $weight = 0, $langcode = NULL) {
  $build = array('nodes' => array());
  $entities_by_view_mode = entity_view_mode_prepare('node', $nodes, $view_mode, $langcode);
  foreach ($entities_by_view_mode as $entity_view_mode => $entities) {
    field_attach_prepare_view('node', $entities, $entity_view_mode, $langcode);
    entity_prepare_view('node', $entities);

    foreach ($entities as $entity) {
      $build['nodes'][$entity->nid] = node_view($entity, $entity_view_mode, $langcode);
    }
  }

  foreach ($nodes as $node) {
    $build['nodes'][$node->nid]['#weight'] = $weight;
    $weight++;
  }
  // Sort here, to preserve the input order of the entities that were passed to
  // this function.
  backdrop_sort($build['nodes'], array('#weight'));
  $build['nodes']['#sorted'] = TRUE;

  return $build;
}