diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php b/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php index 757cdff..632124f 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php @@ -48,7 +48,7 @@ public function synchronizeFields(EntityInterface $entity, $sync_langcode, $orig // If we have no information about what to sync to, if we are creating a new // entity, if we have no translations for the current entity and we are not // creating one, then there is nothing to synchronize. - if (empty($sync_langcode) || $entity->isNew() || (count($translations) < 2 && !$original_langcode)) { + if (empty($sync_langcode) || $entity->isNew() || count($translations) < 2) { return; } diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php index 6e9b82e..4be8830 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php @@ -87,7 +87,6 @@ function testImageFieldSync() { // Populate the required contextual values. $attributes = $this->container->get('request')->attributes; - $attributes->set('working_langcode', $langcode); $attributes->set('source_langcode', $default_langcode); // Populate the test entity with some random initial values. @@ -123,7 +122,7 @@ function testImageFieldSync() { 'alt' => $default_langcode . '_' . $fid . '_' . $this->randomName(), 'title' => $default_langcode . '_' . $fid . '_' . $this->randomName(), ); - $entity->{$this->fieldName}->offsetGet($delta)->setValue($item); + $entity->get($this->fieldName)->offsetGet($delta)->setValue($item); // Store the generated values keying them by fid for easier lookup. $values[$default_langcode][$fid] = $item; @@ -134,6 +133,7 @@ function testImageFieldSync() { // items will be one less than the original values to check that only the // translated ones will be preserved. In fact we want the same fids and // items order for both languages. + $translation = $entity->getTranslation($langcode); for ($delta = 0; $delta < $this->cardinality - 1; $delta++) { // Simulate a field reordering: items are shifted of one position ahead. // The modulo operator ensures we start from the beginning after reaching @@ -148,26 +148,27 @@ function testImageFieldSync() { 'alt' => $langcode . '_' . $fid . '_' . $this->randomName(), 'title' => $langcode . '_' . $fid . '_' . $this->randomName(), ); - $entity->getTranslation($langcode)->{$this->fieldName}->offsetGet($delta)->setValue($item); + $translation->get($this->fieldName)->offsetGet($delta)->setValue($item); // Again store the generated values keying them by fid for easier lookup. $values[$langcode][$fid] = $item; } // Perform synchronization: the translation language is used as source, - // while the default langauge is used as target. - $entity = $this->saveEntity($entity); + // while the default language is used as target. + $entity = $this->saveEntity($translation); + $translation = $entity->getTranslation($langcode); // Check that one value has been dropped from the original values. - $assert = count($entity->{$this->fieldName}) == 2; + $assert = count($entity->get($this->fieldName)) == 2; $this->assertTrue($assert, 'One item correctly removed from the synchronized field values.'); // Check that fids have been synchronized and translatable column values // have been retained. $fids = array(); - foreach ($entity->{$this->fieldName} as $delta => $item) { + foreach ($entity->get($this->fieldName) as $delta => $item) { $value = $values[$default_langcode][$item->fid]; - $source_item = $entity->getTranslation($langcode)->{$this->fieldName}->offsetGet($delta); + $source_item = $translation->get($this->fieldName)->offsetGet($delta); $assert = $item->fid == $source_item->fid && $item->alt == $value['alt'] && $item->title == $value['title']; $this->assertTrue($assert, format_string('Field item @fid has been successfully synchronized.', array('@fid' => $item->fid))); $fids[$item->fid] = TRUE; @@ -183,22 +184,23 @@ function testImageFieldSync() { 'alt' => $langcode . '_' . $removed_fid . '_' . $this->randomName(), 'title' => $langcode . '_' . $removed_fid . '_' . $this->randomName(), ); - $entity->getTranslation($langcode)->{$this->fieldName}->setValue(array_values($values[$langcode])); + $translation->get($this->fieldName)->setValue(array_values($values[$langcode])); // When updating an entity we do not have a source language defined. $attributes->remove('source_langcode'); - $entity = $this->saveEntity($entity); + $entity = $this->saveEntity($translation); + $translation = $entity->getTranslation($langcode); // Check that the value has been added to the default language. - $assert = count($entity->{$this->fieldName}->getValue()) == 3; + $assert = count($entity->get($this->fieldName)->getValue()) == 3; $this->assertTrue($assert, 'One item correctly added to the synchronized field values.'); - foreach ($entity->{$this->fieldName} as $delta => $item) { + foreach ($entity->get($this->fieldName) as $delta => $item) { // When adding an item its value is copied over all the target languages, // thus in this case the source language needs to be used to check the // values instead of the target one. $fid_langcode = $item->fid != $removed_fid ? $default_langcode : $langcode; $value = $values[$fid_langcode][$item->fid]; - $source_item = $entity->getTranslation($langcode)->{$this->fieldName}->offsetGet($delta); + $source_item = $translation->get($this->fieldName)->offsetGet($delta); $assert = $item->fid == $source_item->fid && $item->alt == $value['alt'] && $item->title == $value['title']; $this->assertTrue($assert, format_string('Field item @fid has been successfully synchronized.', array('@fid' => $item->fid))); }