Follow-up of #2382493: Population of default field values in entity translation is incorrect
Problem/Motivation
The current handling of default values in ContentEntityBase::addTranslation()
feels very inefficient: it creates a new fresh entity that gets default values, only to be able to copy those values over to the new translation. Additionally hook_entity_create()
is called when creating an entity translation which is incorrect.
Proposed resolution
- Make sure
ContentEntityStorageBase::doCreate($values)
andContentEntityBase::addTranslation($values)
reuse the same code for the "merge default values into the passed in $values". - Introduce a new
hook_entity_field_values_init()
hook to allow to alter these values regardless of whether we are initializing a new entity or a new entity translation. - Introduce a new
hook_entity_translation_create()
hook to allow to react to entity translation creation.
Remaining tasks
- Validate the proposed solution
- Evaluate whether it can be committed during the RC phase
- Reviews
User interface changes
None
API changes
Mostly additive:
ContentEntityStorageBase
now implements a newContentEntityStorageInterface
.ContentEntityBase::addTranslation()
throws a logic exception if the entity storage handler does not implementContentEntityStorageInterface
.
Data model changes
None