Problem/Motivation
The entity_field_value_definitions tool fails when retrieving field definitions for certain entity types—specifically media and comment—even when a valid bundle is provided.
For example, when executing the tool with:
entity_type_id: media and bundle: image
the tool returns an error:
Tool Plugin executed unsuccessfully: Error retrieving field definitions: Missing bundle for entity type media
This occurs even though the bundle exists and is valid. The issue appears to be in how the tool creates a stub entity to get default field values:
<?php
// Stub version of entity to get default field values.
$entity = $this->entityTypeManager->getStorage($entity_type_id)->create(['type' => $bundle]);
?>Media entities use bundle as the property name for their bundle, not type. Different entity types use different property names for their bundle key, and hardcoding 'type' causes failures for entity types that use a different bundle key.
Steps to reproduce
Install Tool API module with tool_content submodule
Test entity_field_value_definitions tool using tools explorer
Execute the tool with parameters:
- entity_type_id: media
- bundle: image
Observe the error: "Missing bundle for entity type media"
Note: The tool works correctly for nodes and taxonomy terms but fails for media & comment entities
Proposed resolution
Use the entity type's bundle key dynamically instead of hardcoding 'type':
Current code
<?php
// Stub version of entity to get default field values.
$entity = $this->entityTypeManager->getStorage($entity_type_id)->create(['type' => $bundle]);
?>Proposed fix:
<?php
// Stub version of entity to get default field values.
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
$bundle_key = $entity_type->getKey('bundle');
$entity = $this->entityTypeManager->getStorage($entity_type_id)->create([
$bundle_key => $bundle,
]);
?>User interface changes
none
API changes
none
Data model changes
none
Issue fork tool-3563835
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
prabha1997 commentedComment #3
prabha1997 commentedComment #4
prabha1997 commentedComment #5
prabha1997 commentedComment #6
prabha1997 commentedComment #8
prabha1997 commentedComment #9
ajitsThe sub-modules have been moved to "Tool Belt". Moving this issue as well.
@prabha1997 - thank you for your MR. Can you please create it against the new project?