Problem/Motivation
When for a migration no bundle specified is specified, Migration::getDestinationFields()
passes NULL
to
EntityFieldManager::getFieldDefinitions() for $bundle
parameter, but that should be a string.
This results into an error when there is the following custom code defined:
/**
* Implements hook_entity_bundle_field_info_alter().
*/
function mymodule_entity_bundle_field_info_alter(array &$fields, EntityTypeInterface $entity_type, string $bundle): void {
The error is then:
TypeError: mymodule_entity_bundle_field_info_alter(): Argument #3 ($bundle) must be of type string, null given
For user migrations, specifying a bundle is not needed, because the user entity type does not support bundles.
For other entity types that do support bundles, the UI currently does require the user to specify a bundle, but existing migrations (created manually in a yaml file) are not guaranteed to have it. In these situations, EntityFieldManager::getBaseFieldDefinitions()
should be called instead.
Steps to reproduce
- Create a user migration.
- Implement
hook_entity_bundle_field_info_alter()
in a custom module and set the type hint "string" for the $bundle
parameter.
Or:
- In a YAML file, create a migration for node and don't specify the bundle.
- Implement
hook_entity_bundle_field_info_alter()
in a custom module and set the type hint "string" for the $bundle
parameter.
Proposed resolution
In Migration::getDestinationFields()
check if $entity_bundle
is NULL
. If so, check if the entity type supports bundles. If not, pass $entity_type_id
as the bundle to EntityFieldManager::getFieldDefinitions()
. Else call EntityFieldManager::getBaseFieldDefinitions()
instead.
Add test coverage for above two situations.
Remaining tasks
User interface changes
API changes
Data model changes