diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php index a3ccf13..b964d85 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php @@ -78,10 +78,14 @@ public function buildEntity(array $form, array &$form_state) { $translation = $entity->getTranslation($this->getFormLangcode($form_state), FALSE); $definitions = $translation->getPropertyDefinitions(); foreach ($values_excluding_fields as $key => $value) { - // @TODO Remove EntityBCDecorator condition once the decorator is removed. - if (isset($definitions[$key]) || $entity instanceof EntityBCDecorator) { + if (isset($definitions[$key])) { $translation->$key = $value; } + elseif ($entity instanceof EntityBCDecorator) { + // Handle yet undefined properties. + // @todo Remove once EntityBCDecorator is removed. + $entity->$key = $value; + } } // Invoke all specified builders for copying form values to entity fields. diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php index 44b56f5..a2e7927 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php @@ -67,7 +67,10 @@ protected function getNewEntityValues($langcode) { /** * Overrides \Drupal\translation_entity\Tests\EntityTranslationUITest::getFormSubmitAction(). */ - protected function getFormSubmitAction() { + protected function getFormSubmitAction(EntityInterface $entity) { + if ($entity->status) { + return t('Save and unpublish'); + } return t('Save and keep unpublished'); } @@ -123,7 +126,7 @@ protected function assertAuthoringInfo() { 'name' => $user->name, 'date' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'), ); - $this->drupalPost($path, $edit, $this->getFormSubmitAction(), array('language' => $languages[$langcode])); + $this->drupalPost($path, $edit, $this->getFormSubmitAction($entity), array('language' => $languages[$langcode])); } $entity = entity_load($this->entityType, $this->entityId, TRUE); diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationUITest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationUITest.php index 3a9e15b..16eb88b 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationUITest.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationUITest.php @@ -66,7 +66,7 @@ protected function assertBasicTranslation() { $base_path = $this->controller->getBasePath($entity); $path = $langcode . '/' . $base_path . '/translations/add/' . $default_langcode . '/' . $langcode; - $this->drupalPost($path, $this->getEditValues($values, $langcode), $this->getFormSubmitAction()); + $this->drupalPost($path, $this->getEditValues($values, $langcode), $this->getFormSubmitAction($entity)); if ($this->testLanguageSelector) { $this->assertNoFieldByXPath('//select[@id="edit-langcode"]', NULL, 'Language selector correclty disabled on translations.'); } @@ -83,7 +83,7 @@ protected function assertBasicTranslation() { // Add another translation and mark the other ones as outdated. $values[$langcode] = $this->getNewEntityValues($langcode); $edit = $this->getEditValues($values, $langcode) + array('translation_entity[retranslate]' => TRUE); - $this->drupalPost($path, $edit, $this->getFormSubmitAction()); + $this->drupalPost($path, $edit, $this->getFormSubmitAction($entity)); $entity = entity_load($this->entityType, $this->entityId, TRUE); // Check that the entered values have been correctly stored. @@ -108,7 +108,7 @@ protected function assertOutdatedStatus() { // Mark translations as outdated. $edit = array('translation_entity[retranslate]' => TRUE); - $this->drupalPost($langcode . '/' . $this->controller->getEditPath($entity), $edit, $this->getFormSubmitAction()); + $this->drupalPost($langcode . '/' . $this->controller->getEditPath($entity), $edit, $this->getFormSubmitAction($entity)); $entity = entity_load($this->entityType, $this->entityId, TRUE); // Check that every translation has the correct "outdated" status. @@ -122,7 +122,7 @@ protected function assertOutdatedStatus() { else { $this->assertFieldByXPath('//input[@name="translation_entity[outdated]"]', TRUE, 'The translate flag is checked by default.'); $edit = array('translation_entity[outdated]' => FALSE); - $this->drupalPost($path, $edit, $this->getFormSubmitAction()); + $this->drupalPost($path, $edit, $this->getFormSubmitAction($entity)); $this->drupalGet($path); $this->assertFieldByXPath('//input[@name="translation_entity[retranslate]"]', FALSE, 'The retranslate flag is now shown.'); $entity = entity_load($this->entityType, $this->entityId, TRUE); @@ -142,7 +142,7 @@ protected function assertPublishedStatus() { foreach ($this->langcodes as $index => $langcode) { if ($index > 0) { $edit = array('translation_entity[status]' => FALSE); - $this->drupalPost($langcode . '/' . $path, $edit, $this->getFormSubmitAction()); + $this->drupalPost($langcode . '/' . $path, $edit, $this->getFormSubmitAction($entity)); $entity = entity_load($this->entityType, $this->entityId, TRUE); $this->assertFalse($entity->translation[$langcode]['status'], 'The translation has been correctly unpublished.'); } @@ -173,7 +173,7 @@ protected function assertAuthoringInfo() { 'translation_entity[created]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'), ); $prefix = $index > 0 ? $langcode . '/' : ''; - $this->drupalPost($prefix . $path, $edit, $this->getFormSubmitAction()); + $this->drupalPost($prefix . $path, $edit, $this->getFormSubmitAction($entity)); } $entity = entity_load($this->entityType, $this->entityId, TRUE); @@ -189,7 +189,7 @@ protected function assertAuthoringInfo() { 'translation_entity[name]' => $this->randomName(12), 'translation_entity[created]' => $this->randomName(), ); - $this->drupalPost($path, $edit, $this->getFormSubmitAction()); + $this->drupalPost($path, $edit, $this->getFormSubmitAction($entity)); $this->assertTrue($this->xpath('//div[@id="messages"]//div[contains(@class, "error")]//ul'), 'Invalid values generate a list of form errors.'); $this->assertEqual($entity->translation[$langcode]['uid'] == $values[$langcode]['uid'], 'Translation author correctly kept.'); $this->assertEqual($entity->translation[$langcode]['created'] == $values[$langcode]['created'], 'Translation date correctly kept.'); @@ -235,8 +235,14 @@ protected function getEditValues($values, $langcode, $new = FALSE) { /** * Returns the form action value to be used to submit the entity form. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity being tested. + * + * @return string + * Name of the button to hit. */ - protected function getFormSubmitAction() { + protected function getFormSubmitAction(EntityInterface $entity) { return t('Save'); } @@ -252,6 +258,8 @@ protected function getFormSubmitAction() { * The translation object to act on. */ protected function getTranslation(EntityInterface $entity, $langcode) { + // @todo remove once EntityBCDecorator is gone. + $entity = $entity->getOriginalEntity(); return $entity instanceof EntityNG ? $entity->getTranslation($langcode, FALSE) : $entity; } @@ -270,7 +278,8 @@ protected function getTranslation(EntityInterface $entity, $langcode) { */ protected function getValue(ComplexDataInterface $translation, $property, $langcode) { $key = $property == 'user_id' ? 'target_id' : 'value'; - if (($translation instanceof EntityInterface) && !($translation instanceof EntityNG)) { + // @todo remove EntityBCDecorator condition once EntityBCDecorator is gone. + if (($translation instanceof EntityInterface) && !($translation instanceof EntityNG) && !($translation instanceof EntityBCDecorator)) { return is_array($translation->$property) ? $translation->{$property}[$langcode][0][$key] : $translation->$property; } else { diff --git a/core/modules/translation_entity/translation_entity.module b/core/modules/translation_entity/translation_entity.module index e005b94..190f038 100644 --- a/core/modules/translation_entity/translation_entity.module +++ b/core/modules/translation_entity/translation_entity.module @@ -613,6 +613,8 @@ function translation_entity_form_alter(array &$form, array &$form_state) { // Handle fields shared between translations when there is at least one // translation available or a new one is being created. if (!$entity->isNew() && (!isset($translations[$form_langcode]) || count($translations) > 1)) { + // @todo remove once EntityBCDecorator is gone. + $entity = $entity->getOriginalEntity(); if ($entity instanceof EntityNG) { foreach ($entity->getPropertyDefinitions() as $property_name => $definition) { if (isset($form[$property_name])) { diff --git a/core/modules/translation_entity/translation_entity.pages.inc b/core/modules/translation_entity/translation_entity.pages.inc index b64fbcb..364a568 100644 --- a/core/modules/translation_entity/translation_entity.pages.inc +++ b/core/modules/translation_entity/translation_entity.pages.inc @@ -240,6 +240,8 @@ function translation_entity_edit_page(EntityInterface $entity, Language $languag function translation_entity_prepare_translation(EntityInterface $entity, Language $source, Language $target) { // @todo Unify field and property handling. $instances = field_info_instances($entity->entityType(), $entity->bundle()); + // @todo remove once EntityBCDecorator is gone. + $entity = $entity->getOriginalEntity(); if ($entity instanceof EntityNG) { $source_translation = $entity->getTranslation($source->langcode); $target_translation = $entity->getTranslation($target->langcode);