Maps from storage records to entity objects.
array $records: Associative array of query results, keyed on the entity ID.
boolean $load_revision: (optional) TRUE if the revision should be loaded, defaults to FALSE.
array An array of entity objects implementing the EntityInterface.
protected function mapFromStorageRecords(array $records, $load_revision = FALSE) {
$entities = array();
foreach ($records as $id => $record) {
$entities[$id] = array();
foreach ($record as $name => $value) {
// Skip the item delta and item value levels but let the field assign
// the value as suiting. This avoids unnecessary array hierarchies and
// saves memory here.
$entities[$id][$name][Language::LANGCODE_DEFAULT] = $value;
}
// If we have no multilingual values we can instantiate entity objecs
// right now, otherwise we need to collect all the field values first.
if (!$this->dataTable) {
$bundle = $this->bundleKey ? $record->{$this->bundleKey} : FALSE;
// Turn the record into an entity class.
$entities[$id] = new $this->entityClass($entities[$id], $this->entityType, $bundle);
}
}
$this
->attachPropertyData($entities, $load_revision);
return $entities;
}