function taxonomy_term_view_multiple

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

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

Parameters

$terms: An array of taxonomy terms as returned by taxonomy_term_load_multiple().

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

$weight: An integer representing the weight of the first taxonomy term in the list.

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

Return value

An array in the format expected by drupal_render().

1 call to taxonomy_term_view_multiple()
taxonomy_term_show in modules/taxonomy/taxonomy.module
Generates an array which displays a term detail page.

File

modules/taxonomy/taxonomy.module, line 780

Code

function taxonomy_term_view_multiple($terms, $view_mode = 'teaser', $weight = 0, $langcode = NULL) {
    $build = array();
    $entities_by_view_mode = entity_view_mode_prepare('taxonomy_term', $terms, $view_mode, $langcode);
    foreach ($entities_by_view_mode as $entity_view_mode => $entities) {
        field_attach_prepare_view('taxonomy_term', $entities, $entity_view_mode, $langcode);
        entity_prepare_view('taxonomy_term', $entities, $langcode);
        foreach ($entities as $entity) {
            $build['taxonomy_terms'][$entity->tid] = taxonomy_term_view($entity, $entity_view_mode, $langcode);
        }
    }
    foreach ($terms as $term) {
        $build['taxonomy_terms'][$term->tid]['#weight'] = $weight;
        $weight++;
    }
    // Sort here, to preserve the input order of the entities that were passed to
    // this function.
    uasort($build['taxonomy_terms'], 'element_sort');
    $build['taxonomy_terms']['#sorted'] = TRUE;
    return $build;
}

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