Skip to content
Snippets Groups Projects
Commit c0c17636 authored by Francesco Placella's avatar Francesco Placella
Browse files

Issue #2380285 by amateescu, daffie, gaurav.kapoor, Pavan B S, plach,...

Issue #2380285 by amateescu, daffie, gaurav.kapoor, Pavan B S, plach, tstoeckler: SqlContentEntityStorage::mapFromStorageRecord() should respect the table mapping
parent 26a5a2ab
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -482,25 +482,46 @@ protected function mapFromStorageRecords(array $records, $load_from_revision = F
return [];
}
// Get the names of the fields that are stored in the base table and, if
// applicable, the revision table. Other entity data will be loaded in
// loadFromSharedTables() and loadFromDedicatedTables().
$field_names = $this->tableMapping->getFieldNames($this->baseTable);
if ($this->revisionTable) {
$field_names = array_unique(array_merge($field_names, $this->tableMapping->getFieldNames($this->revisionTable)));
}
$values = [];
foreach ($records as $id => $record) {
$values[$id] = [];
// Skip the item delta and item value levels (if possible) but let the
// field assign the value as suiting. This avoids unnecessary array
// hierarchies and saves memory here.
foreach ($record as $name => $value) {
// Handle columns named [field_name]__[column_name] (e.g for field types
// that store several properties).
if ($field_name = strstr($name, '__', TRUE)) {
$property_name = substr($name, strpos($name, '__') + 2);
$values[$id][$field_name][LanguageInterface::LANGCODE_DEFAULT][$property_name] = $value;
foreach ($field_names as $field_name) {
$field_columns = $this->tableMapping->getColumnNames($field_name);
// Handle field types that store several properties.
if (count($field_columns) > 1) {
foreach ($field_columns as $property_name => $column_name) {
if (property_exists($record, $column_name)) {
$values[$id][$field_name][LanguageInterface::LANGCODE_DEFAULT][$property_name] = $record->{$column_name};
unset($record->{$column_name});
}
}
}
// Handle field types that store only one property.
else {
// Handle columns named directly after the field (e.g if the field
// type only stores one property).
$values[$id][$name][LanguageInterface::LANGCODE_DEFAULT] = $value;
$column_name = reset($field_columns);
if (property_exists($record, $column_name)) {
$values[$id][$field_name][LanguageInterface::LANGCODE_DEFAULT] = $record->{$column_name};
unset($record->{$column_name});
}
}
}
// Handle additional record entries that are not provided by an entity
// field, such as 'isDefaultRevision'.
foreach ($record as $name => $value) {
$values[$id][$name][LanguageInterface::LANGCODE_DEFAULT] = $value;
}
}
// Initialize translations array.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment