public function ClientsHandlerEntityController::load in Web Service Clients 7.3
Overridden to implement factory-by-row pattern.
Overrides EntityAPIControllerExportable::load
See also
DrupalDefaultEntityController#load($ids, $conditions)
File
- includes/
clients.controller.inc, line 39 - Provides a controller building upon the Entity exportable controller but providing features for handler objects.
Class
- ClientsHandlerEntityController
- A controller for entities that function as handlers.
Code
public function load($ids = array(), $conditions = array()) {
// Disable the static cache until we are finished loading entities. This is
// because the parent load() will want to cache the entities it loads as
// plain entities rather than handler entities; after that's been done, we
// can't write out handler entities to cache again without unsetting them
// from the cache or emptying it, both of which are inefficient.
// (We can't use $cache here, as that would disable loading from cache too.)
$this->cache_set = FALSE;
// Call the parent to load the entities.
// This gets us StdClass objects if the entities were not previously cached.
$entities = parent::load($ids, $conditions);
// Copy the loaded entity object to the right class for its type.
$return = array();
foreach ($entities as $name => $plain_entity) {
// Get the class to use.
$class = $this
->getClass($plain_entity);
if ($plain_entity instanceof $class) {
// If the object is already of the correct class, then it was loaded
// from the internal controller cache, and we're done.
$return[$name] = $plain_entity;
}
else {
// Otherwise, we need to remake the object to be of the handler class.
// The connection's __construct() takes over from here.
$entity = new $class((array) $plain_entity, $this->entityType);
$return[$name] = $entity;
}
}
// Turn static caching back on.
$this->cache_set = TRUE;
$this
->cacheSet($return);
return $return;
}