diff --git a/core/modules/views/src/Entity/Render/EntityFieldRenderer.php b/core/modules/views/src/Entity/Render/EntityFieldRenderer.php index 7dc07b9..39ab8d0 100644 --- a/core/modules/views/src/Entity/Render/EntityFieldRenderer.php +++ b/core/modules/views/src/Entity/Render/EntityFieldRenderer.php @@ -125,7 +125,7 @@ public function query(QueryPluginBase $query, $relationship = NULL) { */ protected function buildFields(array $values) { $build = []; - if ($renderable_fields = $this->getRenderableFieldIds()) { + if ($values && $renderable_fields = $this->getRenderableFieldIds()) { // Identify all relationships. We will also need one representative field // for each relationship. $relationhips = []; @@ -138,8 +138,9 @@ protected function buildFields(array $values) { // For each row, and each relationship in the row, retrieve the entity to // be processed, and take the correct translation. $entities = []; - foreach ($values as $result_row) { - foreach ($relationhips as $relationhip_id => $field) { + foreach ($relationhips as $relationhip_id => $field) { + $entities[$relationhip_id] = []; + foreach ($values as $result_row) { $entity = $field->getEntity($result_row); $entities[$relationhip_id][$entity->bundle()][$result_row->index] = $this->getEntityTranslation($entity, $result_row); } @@ -219,9 +220,12 @@ protected function getEntityTranslation(EntityInterface $entity, ResultRow $row) * {@inheritdoc} */ public function preRender(array $result) { - // For efficient preRender() populated $this->build with the render arrays for all fields - // in all rows - $this->build = $this->buildFields($result); + // Leverage multiple-entity building of formatter output, by building the + // render arrays for all fields in all rows before the first field is being + // rendered. + if (!isset($this->build)) { + $this->build = $this->buildFields($result); + } } /**