public function EntityAPIControllerExportable::load in Entity API 7
Overridden to support passing numeric ids as well as names as $ids.
Overrides EntityAPIController::load
1 call to EntityAPIControllerExportable::load()
- EntityAPIControllerExportable::delete in includes/
entity.controller.inc - Overridden to care about reverted entities.
File
- includes/
entity.controller.inc, line 731 - Provides a controller building upon the core controller but providing more features like full CRUD functionality.
Class
- EntityAPIControllerExportable
- A controller implementing exportables stored in the database.
Code
public function load($ids = array(), $conditions = array()) {
$entities = array();
// Only do something if loaded by names.
if (!$ids || $this->nameKey == $this->idKey || is_numeric(reset($ids))) {
return parent::load($ids, $conditions);
}
// Revisions are not statically cached, and require a different query to
// other conditions, so separate the revision id into its own variable.
if ($this->revisionKey && isset($conditions[$this->revisionKey])) {
$revision_id = $conditions[$this->revisionKey];
unset($conditions[$this->revisionKey]);
}
else {
$revision_id = FALSE;
}
$passed_ids = !empty($ids) ? array_flip($ids) : FALSE;
// Care about the static cache.
if ($this->cache && !$revision_id) {
$entities = $this
->cacheGetByName($ids, $conditions);
}
// If any entities were loaded, remove them from the ids still to load.
if ($entities) {
$ids = array_keys(array_diff_key($passed_ids, $entities));
}
$entities_by_id = parent::load($ids, $conditions);
$entities += entity_key_array_by_property($entities_by_id, $this->nameKey);
// Ensure that the returned array is keyed by numeric id and ordered the
// same as the original $ids array and remove any invalid ids.
$return = array();
foreach ($passed_ids as $name => $value) {
if (isset($entities[$name])) {
$return[$entities[$name]->{$this->idKey}] = $entities[$name];
}
}
return $return;
}