public EntityViewBuilder::buildComponents(array &$build, array $entities, array $displays, $view_mode)
Builds the component fields and properties of a set of entities.
Parameters
&$build: The renderable array representing the entity content.
\Drupal\Core\Entity\EntityInterface[] $entities: The entities whose content is being built.
\Drupal\Core\Entity\Display\EntityViewDisplayInterface[] $displays: The array of entity view displays holding the display options configured for the entity components, keyed by bundle name.
string $view_mode: The view mode in which the entity is being viewed.
Overrides EntityViewBuilderInterface::buildComponents
File
- core/lib/Drupal/Core/Entity/EntityViewBuilder.php, line 278
Class
- EntityViewBuilder
- Base class for entity view builders.
Namespace
Drupal\Core\Entity
Code
public function buildComponents(array &$build, array $entities, array $displays, $view_mode) { $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(). $this->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] += $display_build[$id]; } } }
Please login to continue.