diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index adbb047..8b2b4e5 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -333,6 +333,22 @@ public function delete() { } /** + * Implements EntityInterface::removeTranslation(). + */ + public function removeTranslation($langcode) { + $translations = $this->getTranslationLanguages(); + // @todo Handle properties. + // Remove field translations. + foreach (field_info_instances($this->entityType(), $this->bundle()) as $instance) { + $field_name = $instance['field_name']; + $field = field_info_field($field_name); + if ($field['translatable']) { + $this->{$field_name}[$langcode] = array(); + } + } + } + + /** * Implements EntityInterface::createDuplicate(). */ public function createDuplicate() { diff --git a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php index 8f5e521..00b2128 100644 --- a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php +++ b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php @@ -277,6 +277,13 @@ public function delete() { return $this->decorated->delete(); } + + /** + * Forwards the call to the decorated entity. + */ + public function removeTranslation($langcode) { + return $this->decorated->removeTranslation($langcode); + } /** * Forwards the call to the decorated entity. */ diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index 94ecc3b..5f79df2 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -147,6 +147,14 @@ public function save(); public function delete(); /** + * Removes the translation values from the given entity. + * + * @param string $langcode + * The language code identifying the translation being deleted. + */ + public function removeTranslation($langcode); + + /** * Creates a duplicate of the entity. * * @return Drupal\Core\Entity\EntityInterface diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index b798bcf..20c2b19 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -346,6 +346,16 @@ public function getTranslationLanguages($include_default = TRUE) { } /** + * Overrides Entity::removeTranslation(). + */ + public function removeTranslation($langcode) { + $translation = $this->getTranslation($langcode); + foreach ($translation->getPropertyDefinitions() as $property_name => $langcode) { + $translation->$property_name = array(); + } + } + + /** * Overrides Entity::translations(). * * @todo: Remove once Entity::translations() gets removed. diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php index 36202eb..820ff85 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php @@ -42,22 +42,6 @@ public function __construct($entity_type, $entity_info) { } /** - * Implements EntityTranslationControllerInterface::removeTranslation(). - */ - public function removeTranslation(EntityInterface $entity, $langcode) { - $translations = $entity->getTranslationLanguages(); - // @todo Handle properties. - // Remove field translations. - foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { - $field_name = $instance['field_name']; - $field = field_info_field($field_name); - if ($field['translatable']) { - $entity->{$field_name}[$langcode] = array(); - } - } - } - - /** * Implements EntityTranslationControllerInterface::retranslate(). */ public function retranslate(EntityInterface $entity, $langcode = NULL) { diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerInterface.php b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerInterface.php index ed08fc0..3bd52ca 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerInterface.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerInterface.php @@ -156,16 +156,6 @@ public function getTranslationAccess(EntityInterface $entity, $langcode); public function getSourceLangcode(array $form_state); /** - * Removes the translation values from the given entity. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity whose values should be removed. - * @param string $langcode - * The language code identifying the translation being deleted. - */ - public function removeTranslation(EntityInterface $entity, $langcode); - - /** * Marks translations as outdated. * * @param \Drupal\Core\Entity\EntityInterface $entity diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerNG.php b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerNG.php index 4c4e9e6..9461c8c 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerNG.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerNG.php @@ -14,13 +14,4 @@ */ class EntityTranslationControllerNG extends EntityTranslationController { - /** - * Overrides EntityTranslationController::removeTranslation(). - */ - public function removeTranslation(EntityInterface $entity, $langcode) { - $translation = $entity->getTranslation($langcode); - foreach ($translation->getPropertyDefinitions() as $property_name => $langcode) { - $translation->$property_name = array(); - } - } } diff --git a/core/modules/translation_entity/translation_entity.pages.inc b/core/modules/translation_entity/translation_entity.pages.inc index 294c97b..ef09d2f 100644 --- a/core/modules/translation_entity/translation_entity.pages.inc +++ b/core/modules/translation_entity/translation_entity.pages.inc @@ -251,7 +251,7 @@ function translation_entity_delete_confirm_submit(array $form, array &$form_stat $controller = translation_entity_controller($entity->entityType()); // Remove the translated values. - $controller->removeTranslation($entity, $language->langcode); + $entity->removeTranslation($language->langcode); $entity->save(); // Remove any existing path alias for the removed translation.