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 - Builds the component fields and properties of a set of entities.
- 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 - Builds the component fields and properties of a set of entities.
- WorkspaceViewBuilder::buildComponents in core/
modules/ workspaces/ src/ WorkspaceViewBuilder.php - Builds the component fields and properties of a set of entities.
5 methods override EntityViewBuilder::buildComponents()
- BlockViewBuilder::buildComponents in core/
modules/ block/ src/ BlockViewBuilder.php - Builds the component fields and properties of a set of entities.
- 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 - Builds the component fields and properties of a set of entities.
- NodeViewBuilder::buildComponents in core/
modules/ node/ src/ NodeViewBuilder.php - Builds the component fields and properties of a set of entities.
- WorkspaceViewBuilder::buildComponents in core/
modules/ workspaces/ src/ WorkspaceViewBuilder.php - Builds the component fields and properties of a set of entities.
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.