core/lib/Drupal/Core/Entity/EntityViewBuilder.php | 70 +++++++++++------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 4a3ace3..e9d1327 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -89,6 +89,41 @@ public static function createInstance(ContainerInterface $container, EntityTypeI } /** + * {@inheritdoc} + */ + public function buildContent(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { + $entities_by_bundle = array(); + foreach ($entities as $id => $entity) { + // Initialize the field item attributes for the fields being displayed. + // The entity can include fields that are not displayed, and the display + // can include components that are not fields, so we want to act on the + // intersection. However, the entity can have many more fields than are + // displayed, so we avoid the cost of calling $entity->getProperties() + // by iterating the intersection as follows. + foreach ($displays[$entity->bundle()]->getComponents() as $name => $options) { + if ($entity->hasField($name)) { + foreach ($entity->get($name) as $item) { + $item->_attributes = array(); + } + } + } + // Group the entities by bundle. + $entities_by_bundle[$entity->bundle()][$id] = $entity; + } + + // Invoke hook_entity_prepare_view(). + \Drupal::moduleHandler()->invokeAll('entity_prepare_view', array($this->entityTypeId, $entities, $displays, $view_mode)); + + // Let the displays build their render arrays. + foreach ($entities_by_bundle as $bundle => $bundle_entities) { + $display_build = $displays[$bundle]->buildMultiple($bundle_entities); + foreach ($bundle_entities as $id => $entity) { + $build[$id] = array_merge($build[$id], $display_build[$id]); + } + } + } + + /** * Provides entity-specific defaults to the build process. * * @param \Drupal\Core\Entity\EntityInterface $entity @@ -304,41 +339,6 @@ public function buildEntityMultiple(array $build) { /** * {@inheritdoc} */ - public function buildContent(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { - $entities_by_bundle = array(); - foreach ($entities as $id => $entity) { - // Initialize the field item attributes for the fields being displayed. - // The entity can include fields that are not displayed, and the display - // can include components that are not fields, so we want to act on the - // intersection. However, the entity can have many more fields than are - // displayed, so we avoid the cost of calling $entity->getProperties() - // by iterating the intersection as follows. - foreach ($displays[$entity->bundle()]->getComponents() as $name => $options) { - if ($entity->hasField($name)) { - foreach ($entity->get($name) as $item) { - $item->_attributes = array(); - } - } - } - // Group the entities by bundle. - $entities_by_bundle[$entity->bundle()][$id] = $entity; - } - - // Invoke hook_entity_prepare_view(). - \Drupal::moduleHandler()->invokeAll('entity_prepare_view', array($this->entityTypeId, $entities, $displays, $view_mode)); - - // Let the displays build their render arrays. - foreach ($entities_by_bundle as $bundle => $bundle_entities) { - $display_build = $displays[$bundle]->buildMultiple($bundle_entities); - foreach ($bundle_entities as $id => $entity) { - $build[$id] = array_merge($build[$id], $display_build[$id]); - } - } - } - - /** - * {@inheritdoc} - */ public function resetCache(array $entities = NULL) { if (isset($entities)) { // Always invalidate the ENTITY_TYPE_list tag.