function EntityViewBuilder::buildComponents
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/EntityViewBuilder.php \Drupal\Core\Entity\EntityViewBuilder::buildComponents()
- 8.9.x core/lib/Drupal/Core/Entity/EntityViewBuilder.php \Drupal\Core\Entity\EntityViewBuilder::buildComponents()
- 10 core/lib/Drupal/Core/Entity/EntityViewBuilder.php \Drupal\Core\Entity\EntityViewBuilder::buildComponents()
Overrides EntityViewBuilderInterface::buildComponents
5 calls to EntityViewBuilder::buildComponents()
- CommentViewBuilder::buildComponents in core/
modules/ comment/ src/ CommentViewBuilder.php - In addition to modifying the content key on entities, this implementation will also set the comment entity key which all comments carry.
- EntityTestViewBuilder::buildComponents in core/
modules/ system/ tests/ modules/ entity_test/ src/ EntityTestViewBuilder.php - EntityViewBuilder::buildMultiple in core/
lib/ Drupal/ Core/ Entity/ EntityViewBuilder.php - Builds multiple entities' views; augments entity defaults.
- NodeViewBuilder::buildComponents in core/
modules/ node/ src/ NodeViewBuilder.php - WorkspaceViewBuilder::buildComponents in core/
modules/ workspaces/ src/ WorkspaceViewBuilder.php
5 methods override EntityViewBuilder::buildComponents()
- BlockViewBuilder::buildComponents in core/
modules/ block/ src/ BlockViewBuilder.php - CommentViewBuilder::buildComponents in core/
modules/ comment/ src/ CommentViewBuilder.php - In addition to modifying the content key on entities, this implementation will also set the comment entity key which all comments carry.
- EntityTestViewBuilder::buildComponents in core/
modules/ system/ tests/ modules/ entity_test/ src/ EntityTestViewBuilder.php - NodeViewBuilder::buildComponents in core/
modules/ node/ src/ NodeViewBuilder.php - WorkspaceViewBuilder::buildComponents in core/
modules/ workspaces/ src/ WorkspaceViewBuilder.php
File
-
core/
lib/ Drupal/ Core/ Entity/ EntityViewBuilder.php, line 315
Class
- EntityViewBuilder
- Base class for entity view builders.
Namespace
Drupal\Core\EntityCode
public function buildComponents(array &$build, array $entities, array $displays, $view_mode) {
$entities_by_bundle = [];
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 = [];
}
}
}
// Group the entities by bundle.
$entities_by_bundle[$entity->bundle()][$id] = $entity;
}
// Invoke hook_entity_prepare_view().
$this->moduleHandler()
->invokeAll('entity_prepare_view', [
$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];
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.