'The "" entity type does not exist' when querying on referenced entity fields

Created on 7 December 2018, over 5 years ago
Updated 10 June 2024, 15 days ago

When querying for a DER field, the addField function in Tables returns an error because it is unable to fetch the field's entity type id.

$target_definition = $propertyDefinitions[$relationship_specifier]->getTargetDefinition();
if (!$entity_type_id && $target_definition instanceof EntityDataDefinitionInterface) {
  $entity_type_id = $target_definition->getEntityTypeId();
}

The definition property in EntityDataDefinition doesn't have any constraints so the getEntityTypeId returns NULL.

public function getEntityTypeId() {
  return isset($this->definition['constraints']['EntityType']) ? $this->definition['constraints']['EntityType'] : NULL;
}
πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States sebkamil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States emb03

    I am seeing this issue on Drupal 10.2.4 using the latest module release versions : * 3.2.0

  • πŸ‡ΊπŸ‡ΈUnited States paulmckibben Atlanta, GA

    I'm also seeing this error when I perform an isEmpty() call in a custom post-update hook.

    e.g.

    foreach ($nodes as $node) {
        if ($node->field_my_der->isEmpty()) {
          $node->field_my_der->setValue([
            'target_id' => 123,
            'target_type' => 'taxonomy_term',
          ]);
          $node->save();
        }
      }
    

    This code fails with the following errors:

    >  [warning] Undefined property: Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem::$entity DynamicEntityReferenceItem.php:495
    >  [error]  Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of /var/www/html/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php).
    
Production build 0.69.0 2024