protected SqlContentEntityStorage::mapFromStorageRecords(array $records, $load_from_revision = FALSE)
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
File
- core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php, line 451
Class
- SqlContentEntityStorage
- A content entity database storage implementation.
Namespace
Drupal\Core\Entity\Sql
Code
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; }
Please login to continue.