diff --git a/entity_translation.api.php b/entity_translation.api.php index 33b447f..a474fa3 100644 --- a/entity_translation.api.php +++ b/entity_translation.api.php @@ -151,3 +151,16 @@ function hook_entity_translation_update($entity_type, $entity, $translation, $va */ function hook_entity_translation_delete($entity_type, $entity, $langcode) { } + +/** + * Allows modules to act when a revision translation is deleted. + * + * @param $entity_type + * The entity type. + * @param $entity + * The entity. + * @param $langcode + * The langcode of the revision translation which was deleted. + */ +function hook_entity_translation_delete_revision($entity_type, $entity, $langcode) { +} diff --git a/entity_translation.install b/entity_translation.install index 1a82a2e..466b4c7 100644 --- a/entity_translation.install +++ b/entity_translation.install @@ -353,7 +353,8 @@ function entity_translation_update_7006() { $spec = array( 'type' => 'int', 'unsigned' => TRUE, - 'not null' => TRUE, + // If we have existing data we cannot enforce this to be NOT NULL. + 'not null' => FALSE, 'description' => 'The entity revision id this translation relates to', ); db_add_field('entity_translation', 'revision_id', $spec); diff --git a/entity_translation.module b/entity_translation.module index cebc965..d3311e2 100644 --- a/entity_translation.module +++ b/entity_translation.module @@ -1154,6 +1154,17 @@ function entity_translation_field_attach_delete($entity_type, $entity) { } /** + * Implements hook_field_attach_delete_revision(). + */ +function entity_translation_field_attach_delete_revision($entity_type, $entity) { + if (entity_translation_enabled($entity_type, $entity)) { + $handler = entity_translation_get_handler($entity_type, $entity); + $handler->removeRevisionTranslations(); + $handler->saveTranslations(); + } +} + +/** * Implementation of hook_field_attach_form(). */ function entity_translation_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) { diff --git a/includes/translation.handler.inc b/includes/translation.handler.inc index b0e0d49..678fe20 100644 --- a/includes/translation.handler.inc +++ b/includes/translation.handler.inc @@ -78,6 +78,11 @@ interface EntityTranslationHandlerInterface { public function removeTranslations(); /** + * Removes all translations from the current revision. + */ + public function removeRevisionTranslations(); + + /** * Initialize the language of the original field values. * * Ensure that the original translation language matches the language assigned @@ -424,7 +429,8 @@ class EntityTranslationDefaultHandler implements EntityTranslationHandlerInterfa } } - $query = db_select('entity_translation_revision', 'et') + $table = $revisionable ? 'entity_translation_revision' : 'entity_translation'; + $query = db_select($table, 'et') ->fields('et') ->condition('entity_type', $entity_type); @@ -746,6 +752,17 @@ class EntityTranslationDefaultHandler implements EntityTranslationHandlerInterfa } /** + * @see EntityTranslationHandlerInterface::removeRevisionTranslations() + */ + public function removeRevisionTranslations() { + $translations_key = $this->getTranslationsKey(); + $keys = array_keys($this->entity->{$translations_key}->data); + $values = array_fill(0, count($keys), array('hook' => 'delete_revision')); + $this->removeTranslation(NULL); + $this->entity->{$translations_key}->hook = array_combine($keys, $values); + } + + /** * @see EntityTranslationHandlerInterface::initOriginalTranslation() */ public function initOriginalTranslation() {