diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 3e58501ae56..e3cd8612466 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -139,7 +139,7 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Con $values[$this->langcodeKey] = $langcode; $values[$this->getEntityType()->getKey('default_langcode')] = FALSE; $this->initFieldValues($translation, $values, $field_names); - $this->invokeHook('translation_create', $entity); + $this->invokeHook('translation_create', $translation); return $translation; } diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php index a5baf4687f7..de62ba73b61 100644 --- a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php @@ -371,6 +371,10 @@ class EntityTranslationTest extends EntityLanguageTestBase { // Save the translation and check that the expected hooks are fired. $translation->save(); $hooks = $this->getHooksInfo(); + + $this->assertEqual($hooks['entity_translation_create'], $langcode, 'The generic entity translation creation hook has fired.'); + $this->assertEqual($hooks[$entity_type . '_translation_create'], $langcode, 'The entity-type-specific entity translation creation hook has fired.'); + $this->assertEqual($hooks['entity_translation_insert'], $langcode, 'The generic entity translation insertion hook has fired.'); $this->assertEqual($hooks[$entity_type . '_translation_insert'], $langcode, 'The entity-type-specific entity translation insertion hook has fired.'); @@ -436,6 +440,10 @@ class EntityTranslationTest extends EntityLanguageTestBase { $this->assertEqual($entity->language()->getId(), $default_langcode, 'The original language has been preserved.'); $translation->save(); $hooks = $this->getHooksInfo(); + + $this->assertEqual($hooks['entity_translation_create'], $langcode2, 'The generic entity translation creation hook has fired.'); + $this->assertEqual($hooks[$entity_type . '_translation_create'], $langcode2, 'The entity-type-specific entity translation creation hook has fired.'); + $this->assertEqual($hooks['entity_translation_insert'], $langcode2, 'The generic entity translation insertion hook has fired.'); $this->assertEqual($hooks[$entity_type . '_translation_insert'], $langcode2, 'The entity-type-specific entity translation insertion hook has fired.'); @@ -483,7 +491,13 @@ class EntityTranslationTest extends EntityLanguageTestBase { $entity->removeTranslation($langcode2); $entity->save(); $hooks = $this->getHooksInfo(); - $this->assertFalse($hooks, 'No hooks are run when adding and removing a translation without storing it.'); + + $this->assertTrue(isset($hooks['entity_translation_create']), 'The generic entity translation creation hook is run when adding and removing a translation without storing it.'); + unset($hooks['entity_translation_create']); + $this->assertTrue(isset($hooks[$entity_type . '_translation_create']), 'The entity-type-specific entity translation creation hook is run when adding and removing a translation without storing it.'); + unset($hooks[$entity_type . '_translation_create']); + + $this->assertFalse($hooks, 'No other hooks beyond the entity translation creation hooks are run when adding and removing a translation without storing it.'); // Check that hooks are fired only when actually storing data. $entity = $this->reloadEntity($entity); @@ -554,6 +568,9 @@ class EntityTranslationTest extends EntityLanguageTestBase { ); $this->assertEqual($translation->description->getValue(), $expected, 'Language-aware default values correctly populated.'); $this->assertEqual($translation->description->getLangcode(), $langcode2, 'Field object has the expected langcode.'); + + // Reset hook firing information. + $this->getHooksInfo(); } /** diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 59e44b6992b..19e42374e89 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -471,6 +471,13 @@ function entity_test_entity_operation_alter(array &$operations, EntityInterface } } +/** + * Implements hook_entity_translation_create(). + */ +function entity_test_entity_translation_create(EntityInterface $translation) { + _entity_test_record_hooks('entity_translation_create', $translation->language()->getId()); +} + /** * Implements hook_entity_translation_insert(). */ @@ -485,6 +492,13 @@ function entity_test_entity_translation_delete(EntityInterface $translation) { _entity_test_record_hooks('entity_translation_delete', $translation->language()->getId()); } +/** + * Implements hook_ENTITY_TYPE_translation_create() for 'entity_test_mul'. + */ +function entity_test_entity_test_mul_translation_create(EntityInterface $translation) { + _entity_test_record_hooks('entity_test_mul_translation_create', $translation->language()->getId()); +} + /** * Implements hook_ENTITY_TYPE_translation_insert() for 'entity_test_mul'. */ @@ -500,7 +514,14 @@ function entity_test_entity_test_mul_translation_delete(EntityInterface $transla } /** - * Implements hook_ENTITY_TYPE_translation_insert() for 'entity_test_mulrev'. + * Implements hook_ENTITY_TYPE_translation_create() for 'entity_test_mul_changed'. + */ +function entity_test_entity_test_mul_changed_translation_create(EntityInterface $translation) { + _entity_test_record_hooks('entity_test_mul_changed_translation_create', $translation->language()->getId()); +} + +/** + * Implements hook_ENTITY_TYPE_translation_insert() for 'entity_test_mul_changed'. */ function entity_test_entity_test_mul_changed_translation_insert(EntityInterface $translation) { _entity_test_record_hooks('entity_test_mul_changed_translation_insert', $translation->language()->getId()); @@ -513,6 +534,13 @@ function entity_test_entity_test_mul_changed_translation_delete(EntityInterface _entity_test_record_hooks('entity_test_mul_changed_translation_delete', $translation->language()->getId()); } +/** + * Implements hook_ENTITY_TYPE_translation_create(). + */ +function entity_test_entity_test_mulrev_translation_create(EntityInterface $translation) { + _entity_test_record_hooks('entity_test_mulrev_translation_create', $translation->language()->getId()); +} + /** * Implements hook_ENTITY_TYPE_translation_insert(). */ @@ -527,6 +555,13 @@ function entity_test_entity_test_mulrev_translation_delete(EntityInterface $tran _entity_test_record_hooks('entity_test_mulrev_translation_delete', $translation->language()->getId()); } +/** + * Implements hook_ENTITY_TYPE_translation_create() for 'entity_test_mulrev_changed'. + */ +function entity_test_entity_test_mulrev_changed_translation_create(EntityInterface $translation) { + _entity_test_record_hooks('entity_test_mulrev_changed_translation_create', $translation->language()->getId()); +} + /** * Implements hook_ENTITY_TYPE_translation_insert() for 'entity_test_mulrev'. */ @@ -541,6 +576,13 @@ function entity_test_entity_test_mulrev_changed_translation_delete(EntityInterfa _entity_test_record_hooks('entity_test_mulrev_changed_translation_delete', $translation->language()->getId()); } +/** + * Implements hook_ENTITY_TYPE_translation_create() for 'entity_test_mul_langcode_key'. + */ +function entity_test_entity_test_mul_langcode_key_translation_create(EntityInterface $translation) { + _entity_test_record_hooks('entity_test_mul_langcode_key_translation_create', $translation->language()->getId()); +} + /** * Implements hook_ENTITY_TYPE_translation_insert() for 'entity_test_mul_langcode_key'. */