diff --git a/core/modules/views/src/Entity/Render/EntityFieldRenderer.php b/core/modules/views/src/Entity/Render/EntityFieldRenderer.php index f2a3778..9224666 100644 --- a/core/modules/views/src/Entity/Render/EntityFieldRenderer.php +++ b/core/modules/views/src/Entity/Render/EntityFieldRenderer.php @@ -194,7 +194,6 @@ protected function buildFields(array $values) { $build = []; if ($values && ($field_ids = $this->getRenderableFieldIds())) { - $entity_type_id = $this->getEntityTypeId(); // Collect the entities for the relationship, fetch the right translation, // and group by bundle. For each result row, the corresponding entity can @@ -226,6 +225,9 @@ protected function buildFields(array $values) { // For each set of fields, build the output by bundle. foreach ($display_sets as $display_fields) { foreach ($entities_by_bundles as $bundle => $bundle_entities) { + // Obtain the entity id from the first value of the bundle. So in the + // case that we have fields from different entities we can detect it. + $entity_type_id = $bundle_entities[key($bundle_entities)]->getEntityTypeId(); // Create the display, and configure the field display options. $display = EntityViewDisplay::create([ 'targetEntityType' => $entity_type_id, diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php index c9ab37a..ea6e436 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -214,7 +214,8 @@ protected function getEntityManager() { * {@inheritdoc} */ public function access(AccountInterface $account) { - $access_control_handler = $this->entityManager->getAccessControlHandler($this->getEntityType()); + $entity_type = $this->configuration['entity_type'] ? $this->configuration['entity_type'] : $this->getEntityType(); + $access_control_handler = $this->entityManager->getAccessControlHandler($entity_type); return $access_control_handler->fieldAccess('view', $this->getFieldDefinition(), $account); } @@ -790,7 +791,8 @@ protected function getEntityFieldRenderer() { } } if (!isset($this->entityFieldRenderer)) { - $entity_type = $this->entityManager->getDefinition($this->getEntityType()); + $entity_type = $this->configuration['entity_type'] ? $this->configuration['entity_type'] : $this->getEntityType(); + $entity_type = $this->entityManager->getDefinition($entity_type); $this->entityFieldRenderer = new EntityFieldRenderer($this->view, $this->relationship, $this->languageManager, $entity_type, $this->entityManager); } }