diff -u b/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php b/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php --- b/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/FieldTranslationSynchronizer.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManager; +use Drupal\Core\Entity\EntityNG; use Drupal\Core\Entity\Field\FieldInterface; /** @@ -37,6 +38,12 @@ * {@inheritdoc} */ public function synchronizeFields(EntityInterface $entity, $sync_langcode, $original_langcode = NULL) { + // Field synchronization is only supported for NG entities. + $entity = $entity->getNGEntity(); + if (!($entity instanceof EntityNG)) { + return; + } + $translations = $entity->getTranslationLanguages(); // If we have no information about what to sync to, if we are creating a new @@ -120,7 +127,7 @@ foreach ($translations as $langcode) { $entity->getTranslation($langcode)->{$field_name}->setValue(array()); } - $entity->getTranslation($sync_langcode)->{$field_name}->setValue($source_items); + $entity->getTranslation($sync_langcode)->{$field_name}->setValue($source_items->getValue()); // Update field translations. foreach ($translations as $langcode) { @@ -160,7 +167,7 @@ // If a synchronized column has changed or has been created from // scratch we need to override the full items array for all languages. elseif ($created) { - $new_values[$delta] = $source_items->offsetGet($delta); + $new_values[$delta] = $source_items->offsetGet($delta)->getValue(); } // Otherwise the current item might have been reordered. elseif (isset($old_delta) && isset($new_delta)) { @@ -169,7 +176,12 @@ // the new values are at least propagated to all the translations. // If the value has only been reordered we just move the old one in // the new position. - $new_values[$delta] = isset($original_field_values[$langcode][$old_delta]) ? $original_field_values[$langcode][$old_delta] : $source_items[$new_delta]; + if (isset($original_field_values[$langcode][$old_delta])) { + $new_values[$delta] = $original_field_values[$langcode][$old_delta]; + } + else { + $new_values[$delta] = $source_items->offsetGet($new_delta)->getValue(); + } } } diff -u b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php --- b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php @@ -99,7 +99,6 @@ 'langcode' => $default_langcode, ); $entity = entity_create($this->entityType, $values); -// $entity = entity_create($this->entityType, $values)->getBCEntity(); // Create some file entities from the generated test files and store them. $values = array(); @@ -169,15 +168,15 @@ // have been retained. $fids = array(); foreach ($entity->{$this->fieldName} as $delta => $item) { - $value = $values[$default_langcode][$item['fid']]; + $value = $values[$default_langcode][$item->fid]; $source_item = $entity->getTranslation($langcode)->{$this->fieldName}->offsetGet($delta); - $assert = $item['fid'] == $source_item['fid'] && $item['alt'] == $value['alt'] && $item['title'] == $value['title']; - debug($source_item['fid'], 'source item fid'); + $assert = $item->fid == $source_item->fid && $item->alt == $value['alt'] && $item->title == $value['title']; + debug($source_item->fid, 'source item fid'); debug($item->fid, 'item fid'); debug($item->getValue(), 'item'); debug($value, 'value'); - $this->assertTrue($assert, format_string('Field item @fid has been successfully synchronized.', array('@fid' => $item['fid']))); - $fids[$item['fid']] = TRUE; + $this->assertTrue($assert, format_string('Field item @fid has been successfully synchronized.', array('@fid' => $item->fid))); + $fids[$item->fid] = TRUE; } // Check that the dropped value is the right one. @@ -204,11 +203,11 @@ // 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']]; + $fid_langcode = $item->fid != $removed_fid ? $default_langcode : $langcode; + $value = $values[$fid_langcode][$item->fid]; $source_item = $entity->getTranslation($langcode)->{$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']))); + $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))); } }