diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index 3b30196..c4c990f 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -1237,7 +1237,9 @@ protected function loadFromDedicatedTables(array &$values, $load_from_revision) foreach ($values as $key => $entity_values) { $bundles[$this->bundleKey ? $entity_values[$this->bundleKey][LanguageInterface::LANGCODE_DEFAULT] : $this->entityTypeId] = TRUE; $ids[] = !$load_from_revision ? $key : $entity_values[$this->revisionKey][LanguageInterface::LANGCODE_DEFAULT]; - $default_langcodes[$key] = $entity_values[$this->langcodeKey][LanguageInterface::LANGCODE_DEFAULT]; + if ($this->langcodeKey && isset($entity_values[$this->langcodeKey][LanguageInterface::LANGCODE_DEFAULT])) { + $default_langcodes[$key] = $entity_values[$this->langcodeKey][LanguageInterface::LANGCODE_DEFAULT]; + } } // Collect impacted fields. @@ -1275,14 +1277,18 @@ protected function loadFromDedicatedTables(array &$values, $load_from_revision) // Field values in default language are stored with // LanguageInterface::LANGCODE_DEFAULT as key. - $langcode = $row->langcode == $default_langcodes[$row->entity_id] ? LanguageInterface::LANGCODE_DEFAULT : $row->langcode; + $langcode = LanguageInterface::LANGCODE_DEFAULT; + if ($this->langcodeKey && isset($default_langcodes[$row->entity_id]) && $row->langcode != $default_langcodes[$row->entity_id]) { + $langcode = $row->langcode; + } + if (!isset($values[$row->entity_id][$field_name][$langcode])) { $values[$row->entity_id][$field_name][$langcode] = array(); } // Ensure that records for non-translatable fields having invalid // languages are skipped. - if ($row->langcode == $default_langcodes[$row->entity_id] || $definitions[$bundle][$field_name]->isTranslatable()) { + if ($row->langcode == LanguageInterface::LANGCODE_DEFAULT || $definitions[$bundle][$field_name]->isTranslatable()) { if ($storage_definition->getCardinality() == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED || count($values[$row->entity_id][$field_name][$langcode]) < $storage_definition->getCardinality()) { $item = array(); // For each column declared by the field, populate the item from the diff --git a/core/modules/field/src/Tests/BulkDeleteTest.php b/core/modules/field/src/Tests/BulkDeleteTest.php index be306e5..fdffb7e 100644 --- a/core/modules/field/src/Tests/BulkDeleteTest.php +++ b/core/modules/field/src/Tests/BulkDeleteTest.php @@ -141,6 +141,11 @@ protected function setUp() { } $this->entities = entity_load_multiple($this->entity_type); foreach ($this->entities as $entity) { + // This test relies on the entities having stale field definitions + // so that the deleted field can be accessed on them. Access the field + // now, so that they are always loaded. + $entity->bf_1->value; + // Also keep track of the entities per bundle. $this->entities_by_bundles[$entity->bundle()][$entity->id()] = $entity; }