Problem/Motivation
ContentEntityStorageBase::createTranslation fires two hooks when a new translation is created: hook_field_values_init and hook_translation_create. hook_field_values_init is invoked with the new entity translation object, but the hook_translation_create is invoked with the previous entity object. Both hooks have been introduced in #2382675: hook_entity_create() affects the data of new translations of existing entities in unexpected and undocumented ways.
The entity API states that the new entity translation is passed, but it is not:
/**
* Acts when creating a new entity translation.
*
* This hook runs after a new entity translation object has just been
* instantiated.
*
* @param \Drupal\Core\Entity\EntityInterface $translation
* The entity object.
*
* @ingroup entity_crud
* @see hook_ENTITY_TYPE_translation_create()
*/
function hook_entity_translation_create(\Drupal\Core\Entity\EntityInterface $translation) {
\Drupal::logger('example')->info('Entity translation created: @label', ['@label' => $translation->label()]);
}
Proposed resolution
Call the hook_translation_create with the new entity translation object.
Remaining tasks
none
User interface changes
none
API changes
none
Data model changes
none
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | interdiff-2-3.txt | 588 bytes | hchonov |
| #3 | 2649602-3.patch | 7.92 KB | hchonov |
| #2 | 2649602-2-failing_test.patch | 7.21 KB | hchonov |
Comments
Comment #2
hchonovComment #3
hchonovThe failing test with the fix.
Comment #4
hchonovComment #5
hchonovComment #6
hchonovOh, I've forgot the interdiff....
Comment #8
gábor hojtsyQuestion is if this would be a "backwards compatible change" in terms of people expecting the new functionality anyway, or not. It would be good to figure this out.
Comment #9
hchonovComment #10
hchonovComment #11
chx commentedThe BC way is
Comment #12
chx commentedBut of course if previous code was unusable then there's no point in keeping BC.
Comment #13
xjmThe D8 core committers all agreed that this sounds like a major bug. Thanks @hchonov for reporting this.
Comment #14
hchonovAdding the tag SprintWeekend2016 in hope someone will review it this sprint weekend.
Comment #15
gábor hojtsyLooks like there is agreement in fixing it this way, the patch looks fine, so let's get this in!
Comment #17
catchThis looks great to me.
It's 8.0.3 release day today, so it can't go in there today, also just in case it did break a contrib module, I think it's worth doing early in a patch release cycle than late.
So committed/pushed to 8.1.x, leaving RTBC for 8.0.x for when the branch is open again.
Comment #19
gábor hojtsyTestbot error with composer.
Comment #20
gábor hojtsyComment #22
catchCherry-picked to 8.0.x, thanks!
Comment #23
xjmComment #25
gábor hojtsyYay!