8.5.x EntityViewBuilder.php EntityViewBuilder::buildMultiple(array $build_list)
8.0.x EntityViewBuilder.php EntityViewBuilder::buildMultiple(array $build_list)
8.1.x EntityViewBuilder.php EntityViewBuilder::buildMultiple(array $build_list)
8.2.x EntityViewBuilder.php EntityViewBuilder::buildMultiple(array $build_list)
8.3.x EntityViewBuilder.php EntityViewBuilder::buildMultiple(array $build_list)
8.4.x EntityViewBuilder.php EntityViewBuilder::buildMultiple(array $build_list)
8.6.x EntityViewBuilder.php EntityViewBuilder::buildMultiple(array $build_list)

Builds multiple entities' views; augments entity defaults.

This function is assigned as a #pre_render callback in ::viewMultiple().

By delaying the building of an entity until the #pre_render processing in drupal_render(), the processing cost of assembling an entity's renderable array is saved on cache-hit requests.


array $build_list: A renderable array containing build information and context for an entity view.

Return value

array The updated renderable array.

See also


2 calls to EntityViewBuilder::buildMultiple()
BlockContentViewBuilder::viewMultiple in core/modules/block_content/src/BlockContentViewBuilder.php
Builds the render array for the provided entities.
EntityViewBuilder::build in core/lib/Drupal/Core/Entity/EntityViewBuilder.php
Builds an entity's view; augments entity defaults.


core/lib/Drupal/Core/Entity/EntityViewBuilder.php, line 241


Base class for entity view builders.




public function buildMultiple(array $build_list) {

  // Build the view modes and display objects.
  $view_modes = array();
  $entity_type_key = "#{$this-&gt;<span class="php-function-or-constant property member-of-self">entityTypeId</span>}";
  $view_hook = "{$this-&gt;<span class="php-function-or-constant property member-of-self">entityTypeId</span>}_view";

  // Find the keys for the ContentEntities in the build; Store entities for
  // rendering by view_mode.
  $children = Element::children($build_list);
  foreach ($children as $key) {
    if (isset($build_list[$key][$entity_type_key])) {
      $entity = $build_list[$key][$entity_type_key];
      if ($entity instanceof FieldableEntityInterface) {
        $view_modes[$build_list[$key]['#view_mode']][$key] = $entity;

  // Build content for the displays represented by the entities.
  foreach ($view_modes as $view_mode => $view_mode_entities) {
    $displays = EntityViewDisplay::collectRenderDisplays($view_mode_entities, $view_mode);
      ->buildComponents($build_list, $view_mode_entities, $displays, $view_mode);
    foreach (array_keys($view_mode_entities) as $key) {

      // Allow for alterations while building, before rendering.
      $entity = $build_list[$key][$entity_type_key];
      $display = $displays[$entity
        ->invokeAll($view_hook, [
        ->invokeAll('entity_view', [
        ->alterBuild($build_list[$key], $entity, $display, $view_mode);

      // Assign the weights configured in the display.
      // @todo: Once https://www.drupal.org/node/1875974 provides the missing
      //   API, only do it for 'extra fields', since other components have
      //   been taken care of in EntityViewDisplay::buildMultiple().
      foreach ($display
        ->getComponents() as $name => $options) {
        if (isset($build_list[$key][$name])) {
          $build_list[$key][$name]['#weight'] = $options['weight'];

      // Allow modules to modify the render array.
      ), $build_list[$key], $entity, $display);
  return $build_list;