Commit b53d68dd authored by catch's avatar catch
Browse files

Issue #2649602 by hchonov: hook_translation_create is not invoked with the new...

Issue #2649602 by hchonov: hook_translation_create is not invoked with the new entity translation but with the previous entity object
parent 0c127c54
......@@ -139,7 +139,7 @@ public function createTranslation(ContentEntityInterface $entity, $langcode, arr
$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;
}
......
......@@ -371,6 +371,10 @@ protected function doTestEntityTranslationAPI($entity_type) {
// 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 @@ protected function doTestEntityTranslationAPI($entity_type) {
$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 @@ protected function doTestEntityTranslationAPI($entity_type) {
$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 @@ protected function doTestEntityTranslationAPI($entity_type) {
);
$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();
}
/**
......
......@@ -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'.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment