protected function SqlContentEntityStorage::mapFromStorageRecords in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php \Drupal\Core\Entity\Sql\SqlContentEntityStorage::mapFromStorageRecords()
Maps from storage records to entity objects, and attaches fields.
Parameters
array $records: Associative array of query results, keyed on the entity ID.
bool $load_from_revision: Flag to indicate whether revisions should be loaded or not.
Return value
array An array of entity objects implementing the EntityInterface.
Overrides EntityStorageBase::mapFromStorageRecords
2 calls to SqlContentEntityStorage::mapFromStorageRecords()
- SqlContentEntityStorage::doLoadRevisionFieldItems in core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorage.php - Actually loads revision field item values from the storage.
- SqlContentEntityStorage::getFromStorage in core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorage.php - Gets entities from the storage.
File
- core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorage.php, line 452 - Contains \Drupal\Core\Entity\Sql\SqlContentEntityStorage.
Class
- SqlContentEntityStorage
- A content entity database storage implementation.
Namespace
Drupal\Core\Entity\SqlCode
protected function mapFromStorageRecords(array $records, $load_from_revision = FALSE) {
if (!$records) {
return array();
}
$values = array();
foreach ($records as $id => $record) {
$values[$id] = array();
// 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;
}
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;
}
}
}
// Initialize translations array.
$translations = array_fill_keys(array_keys($values), array());
// Load values from shared and dedicated tables.
$this
->loadFromSharedTables($values, $translations);
$this
->loadFromDedicatedTables($values, $load_from_revision);
$entities = array();
foreach ($values as $id => $entity_values) {
$bundle = $this->bundleKey ? $entity_values[$this->bundleKey][LanguageInterface::LANGCODE_DEFAULT] : FALSE;
// Turn the record into an entity class.
$entities[$id] = new $this->entityClass($entity_values, $this->entityTypeId, $bundle, array_keys($translations[$id]));
}
return $entities;
}