diff -u b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php --- b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -645,7 +645,7 @@ $revision_query = $this->database->insert($revision_name)->fields($columns); foreach ($entity->getTranslationLanguages() as $langcode => $language) { - $items = (array) $entity->getTranslation($langcode)->{$field_name}->getValue(); + $items = $entity->getTranslation($langcode)->{$field_name}->getValue(); $delta_count = 0; foreach ($items as $delta => $item) { // We now know we have someting to insert. diff -u b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ConfigTestTranslationUITest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ConfigTestTranslationUITest.php --- b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ConfigTestTranslationUITest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ConfigTestTranslationUITest.php @@ -54,22 +54,24 @@ } /** - * Overrides ContentTranslationTest::testTranslationUI(). + * Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::::testTranslationUI(). * - * @todo This override is a copy-paste of parts of the parent method. Turn - * ConfigTest into a properly translatable entity and remove this override. + * @todo Config entities are not translatable, but Content Translation module + * doesn't have a clean way to enforce that, so this test is here to ensure + * the module doesn't interfere with basic config entity storage. + * Reconsider the purpose of this test after http://drupal.org/node/2004244 + * and either remove it or rewrite it to more clearly test what is needed. */ function testTranslationUI() { // Create a new test entity with original values in the default language. $default_langcode = $this->langcodes[0]; - $values[$default_langcode] = $this->getNewEntityValues($default_langcode); - $id = $this->createEntity($values[$default_langcode], $default_langcode); + $values = $this->getNewEntityValues($default_langcode); + $id = $this->createEntity($values, $default_langcode); $entity = entity_load($this->entityType, $id, TRUE); $this->assertTrue($entity, 'Entity found in the database.'); - foreach ($values[$default_langcode] as $property => $value) { + foreach ($values as $property => $value) { $stored_value = $entity->{$property}; - $value = is_array($value) ? $value[0]['value'] : $value; $message = format_string('@property correctly stored in the default language.', array('@property' => $property)); $this->assertIdentical($stored_value, $value, $message); } diff -u b/core/modules/field/field.multilingual.inc b/core/modules/field/field.multilingual.inc --- b/core/modules/field/field.multilingual.inc +++ b/core/modules/field/field.multilingual.inc @@ -89,8 +89,7 @@ foreach ($field_langcodes as $field_name => $field_langcode) { // If the requested language is defined for the current field use it, // otherwise search for a fallback value among the fallback candidates. - $value = $entity->hasTranslation($langcode) ? $entity->getTranslation($langcode)->$field_name->getValue() : NULL; - if (!empty($value) && is_array($value) && array_filter($value, function($value) { return array_filter($value); })) { + if (_field_translated_value_exists($entity, $langcode, $field_name)) { $field_langcodes[$field_name] = $langcode; } else { @@ -99,8 +98,7 @@ $fallback_candidates = language_fallback_get_candidates(); } foreach ($fallback_candidates as $fallback_langcode) { - $value = $entity->hasTranslation($fallback_langcode) ? $entity->getTranslation($fallback_langcode)->$field_name->getValue() : NULL; - if (!empty($value) && is_array($value) && array_filter($value, function($value) { return array_filter($value); })) { + if (_field_translated_value_exists($entity, $fallback_langcode, $field_name)) { $field_langcodes[$field_name] = $fallback_langcode; break; } @@ -311,8 +309,7 @@ // if the field translation is not available. It is up to translation // handlers to implement language fallback rules. foreach (field_info_instances($entity_type, $bundle) as $instance) { - $value = $entity->hasTranslation($langcode) ? $entity->getTranslation($langcode)->{$instance['field_name']}->getValue() : NULL; - if (!empty($value) && is_array($value) && array_filter($value, function($value) { return array_filter($value); })) { + if (_field_translated_value_exists($entity, $langcode, $instance['field_name'])) { $display_langcode[$instance['field_name']] = $langcode; } else { @@ -356,0 +354,13 @@ + +/** + * Returns TRUE if a non-empty value exists for a given entity/language/field. + */ +function _field_translated_value_exists(EntityInterface $entity, $langcode, $field_name) { + if (!$entity->hasTranslation($langcode)) { + return FALSE; + } + $field = $entity->getTranslation($langcode)->$field_name; + $field->filterEmptyValues(); + $value = $field->getValue(); + return !empty($value); +}