function node_view_multiple

Same name in other branches
  1. 8.9.x core/modules/node/node.module \node_view_multiple()

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

Parameters

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

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

$weight: An 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 drupal_render().

5 calls to node_view_multiple()
blog_page_last in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of all users.
blog_page_user in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of a given user.
node_page_default in modules/node/node.module
Menu callback: Generates a listing of promoted nodes.
node_show in modules/node/node.module
Generates an array which displays a node detail page.
taxonomy_term_page in modules/taxonomy/taxonomy.pages.inc
Menu callback; displays all nodes associated with a term.

File

modules/node/node.module, line 2661

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, $langcode);
        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.
    uasort($build['nodes'], 'element_sort');
    $build['nodes']['#sorted'] = TRUE;
    return $build;
}

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