diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index 882694d..74d921f 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\Query\QueryException; use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; use Drupal\Core\Entity\Sql\TableMappingInterface; +use Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface; use Drupal\Core\TypedData\DataReferenceDefinitionInterface; /** @@ -264,9 +265,9 @@ public function addField($field, $type, $langcode) { if (isset($propertyDefinitions[$relationship_specifier]) && $propertyDefinitions[$relationship_specifier] instanceof DataReferenceDefinitionInterface) { // If it is, use the entity type if specified already, otherwise use // the definition. - if (!$entity_type_id) { - $entity_type_id = $propertyDefinitions[$relationship_specifier]->getTargetDefinition() - ->getEntityTypeId(); + $target_definition = $propertyDefinitions[$relationship_specifier]->getTargetDefinition(); + if (!$entity_type_id && $target_definition instanceof EntityDataDefinitionInterface) { + $entity_type_id = $target_definition->getEntityTypeId(); } $entity_type = $this->entityManager->getDefinition($entity_type_id); $field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id);