protected SqlContentEntityStorage::mapFromStorageRecords(array $records, $load_from_revision = FALSE)
Maps from storage records to entity objects, and attaches fields.
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.
array An array of entity objects implementing the EntityInterface.
Overrides EntityStorageBase::mapFromStorageRecords
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; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Sql!SqlContentEntityStorage.php/function/SqlContentEntityStorage::mapFromStorageRecords/8.1.x