diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index fe00ef3..34126c2 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -344,6 +344,22 @@ public function delete() { } /** + * Implements \Drupal\Core\Entity\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 \Drupal\Core\Entity\EntityInterface::createDuplicate(). */ public function createDuplicate() { diff --git a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php index 57215cb..a147555 100644 --- a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php +++ b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php @@ -316,6 +316,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 34038e9..754df27 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -156,6 +156,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 8763f6d..aaa0eae 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -354,6 +354,16 @@ public function getTranslationLanguages($include_default = TRUE) { } /** + * Overrides \Drupal\Core\Entity\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 eaecec9..c5b5ba0 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 a42a019..d98fa5d 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerInterface.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerInterface.php @@ -160,16 +160,6 @@ public function getTranslationAccess(EntityInterface $entity, $op); 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 fd007cd..dfcc815 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerNG.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationControllerNG.php @@ -21,14 +21,4 @@ public function getAccess(EntityInterface $entity, $op) { return $entity->access($op); } - /** - * Overrides \Drupal\translation_entity\EntityTranslationControllerInterface::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 b6c327c..7b63ec6 100644 --- a/core/modules/translation_entity/translation_entity.pages.inc +++ b/core/modules/translation_entity/translation_entity.pages.inc @@ -287,7 +287,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. diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php index ab5a00f..358e2da 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -985,6 +985,13 @@ public function delete() { } /** + * Implements \Drupal\Core\Entity\EntityInterface::removeTranslation(). + */ + public function removeTranslation($langcode) { + return $this->__call(__FUNCTION__, func_get_args()); + } + + /** * Implements \Drupal\Core\Entity\EntityInterface::save(). */ public function save() {