diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index 355114e..8b53e2d 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -228,6 +228,13 @@ protected function getTranslatedField($property_name, $langcode) { if (isset($this->values[$property_name][$langcode])) { $value = $this->values[$property_name][$langcode]; } + // @todo Remove this once the BC decorator is gone. + elseif ($property_name != 'langcode') { + $default_langcode = $this->language()->langcode; + if ($langcode == Language::LANGCODE_DEFAULT && isset($this->values[$property_name][$default_langcode])) { + $value = $this->values[$property_name][$default_langcode]; + } + } $this->fields[$property_name][$langcode] = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php index 0f44412..eda412f 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php @@ -243,7 +243,6 @@ function testTranslatableFieldSaveLoad() { $entity->getTranslation($langcode)->{$this->field_name}->setValue($field_translations[$langcode]); } - // Save and reload the field translations. field_attach_insert($entity); $entity = entity_create($entity_type, array('id' => $id, 'revision_id' => $revision_id, 'type' => $this->instance['bundle'])); @@ -289,9 +288,10 @@ function testTranslatableFieldSaveLoad() { sort($field_langcodes); $this->assertEqual($translation_langcodes, $field_langcodes, 'Missing translations did not get a default value.'); - foreach ($entity->getTranslationLanguages() as $langcode => $language) { - $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $instance['default_value'], format_string('Default value correctly populated for language %language.', array('%language' => $langcode))); - } + // @todo Test every translation once the Entity Translation API allows for + // multilingual defaults. + $langcode = $entity->language()->langcode; + $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $instance['default_value'], format_string('Default value correctly populated for language %language.', array('%language' => $langcode))); // Check that explicit empty values are not overridden with default values. foreach (array(NULL, array()) as $empty_items) { @@ -402,7 +402,7 @@ function testFieldDisplayLanguage() { \Drupal::state()->set('field_test.language_fallback', FALSE); $entity->getTranslation($requested_langcode)->{$this->field_name}->value = mt_rand(1, 127); drupal_static_reset('field_language'); - $display_langcode = field_language($entity, $this->field_name, $requested_langcode); + $display_langcode = field_language($entity->getBCEntity(), $this->field_name, $requested_langcode); $this->assertEqual($display_langcode, $requested_langcode, 'Display language behave correctly when language fallback is disabled'); } }