class WSEntityAPIController in Web Service Data 7
WSEntityAPIController extends and overrides most EntityAPIController features
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface
- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
- class \WSEntityAPIController implements WSEntityAPIControllerInterface
- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
Expanded class hierarchy of WSEntityAPIController
File
- modules/
wsentities/ includes/ wsentity.controller.inc, line 18 - Provides a controller building upon the core controller but providing more features like full CRUD functionality.
View source
class WSEntityAPIController extends EntityAPIController implements WSEntityAPIControllerInterface {
protected $cacheComplete = FALSE;
protected $bundleKey;
public function __construct($entityType) {
/**
TODO: Load entity config object here
TODO: Find a method of finding out which config object goes with this entity.
**/
parent::__construct($entityType);
}
/**
* WS Get's the entity
*/
public function query($ids, $conditions, $revision_id = FALSE) {
/*
TODO: WS RETRIEVE
*/
return $result;
}
/**
* Implements EntityAPIControllerInterface.
*
* WS Delete's the entity
*
* @param $transaction
* Optionally a DatabaseTransaction object to use. Allows overrides to pass
* in their transaction object.
*/
public function delete($ids, DatabaseTransaction $transaction = NULL) {
$entities = $ids ? $this
->load($ids) : FALSE;
if (!$entities) {
// Do nothing, in case invalid or no ids have been passed.
return;
}
// This transaction causes troubles on MySQL, see
// http://drupal.org/node/1007830. So we deactivate this by default until
// is shipped in a point release.
// $transaction = isset($transaction) ? $transaction : db_transaction();
try {
$ids = array_keys($entities);
/*
TODO: WS delete
db_delete($this->entityInfo['base table'])
->condition($this->idKey, $ids, 'IN')
->execute();
*/
// Reset the cache as soon as the changes have been applied.
$this
->resetCache($ids);
foreach ($entities as $id => $entity) {
$this
->invoke('delete', $entity);
}
// Ignore slave server temporarily.
db_ignore_slave();
} catch (Exception $e) {
if (isset($transaction)) {
$transaction
->rollback();
}
watchdog_exception($this->entityType, $e);
throw $e;
}
}
/**
* Implements EntityAPIControllerInterface.
*
* @param $transaction
* Optionally a DatabaseTransaction object to use. Allows overrides to pass
* in their transaction object.
*/
public function save($entity, DatabaseTransaction $transaction = NULL) {
$transaction = isset($transaction) ? $transaction : db_transaction();
try {
// Load the stored entity, if any.
if (!empty($entity->{$this->idKey}) && !isset($entity->original)) {
// In order to properly work in case of name changes, load the original
// entity using the id key if it is available.
$entity->original = entity_load_unchanged($this->entityType, $entity->{$this->idKey});
}
$this
->invoke('presave', $entity);
if (!empty($entity->{$this->idKey}) && empty($entity->is_new)) {
/*
TODO: WS PUT
$return = drupal_write_record($this->entityInfo['base table'], $entity, $this->idKey);
*/
$this
->resetCache(array(
$entity->{$this->idKey},
));
$this
->invoke('update', $entity);
}
else {
/*
TODO: WS POST
$return = drupal_write_record($this->entityInfo['base table'], $entity);
*/
$this
->invoke('insert', $entity);
}
// Ignore slave server temporarily.
db_ignore_slave();
unset($entity->is_new);
unset($entity->original);
return $return;
} catch (Exception $e) {
$transaction
->rollback();
watchdog_exception($this->entityType, $e);
throw $e;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalDefaultEntityController:: |
protected | property | Whether this entity type should use the static cache. | |
DrupalDefaultEntityController:: |
protected | property | Static cache of entities, keyed by entity ID. | |
DrupalDefaultEntityController:: |
protected | property | Array of information about the entity. | |
DrupalDefaultEntityController:: |
protected | property | Entity type for this controller instance. | |
DrupalDefaultEntityController:: |
protected | property | Additional arguments to pass to hook_TYPE_load(). | |
DrupalDefaultEntityController:: |
protected | property | Name of the entity's ID field in the entity database table. | |
DrupalDefaultEntityController:: |
protected | property | Name of entity's revision database table field, if it supports revisions. | |
DrupalDefaultEntityController:: |
protected | property | The table that stores revisions, if the entity supports revisions. | |
DrupalDefaultEntityController:: |
protected | function | Attaches data to entities upon loading. | 4 |
DrupalDefaultEntityController:: |
protected | function | Gets entities from the static cache. | 1 |
DrupalDefaultEntityController:: |
protected | function | Stores entities in the static entity cache. | |
DrupalDefaultEntityController:: |
protected | function | Ensures integer entity IDs are valid. | |
DrupalDefaultEntityController:: |
protected | function | Callback for array_filter that removes non-integer IDs. | |
EntityAPIController:: |
protected | property | ||
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
|
EntityAPIController:: |
protected | function |
Overrides DrupalDefaultEntityController::buildQuery(). Overrides DrupalDefaultEntityController:: |
1 |
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
|
EntityAPIController:: |
public | function |
Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface:: |
|
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
1 |
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
|
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
1 |
EntityAPIController:: |
public | function |
Overridden. Overrides DrupalDefaultEntityController:: |
1 |
EntityAPIController:: |
protected | function | Renders a single entity property. | |
EntityAPIController:: |
public | function |
Overrides DrupalDefaultEntityController::resetCache(). Overrides DrupalDefaultEntityController:: |
1 |
EntityAPIController:: |
protected | function | Saves an entity revision. | |
EntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: |
1 |
WSEntityAPIController:: |
protected | property |
Overrides EntityAPIController:: |
|
WSEntityAPIController:: |
protected | property |
Overrides EntityAPIController:: |
|
WSEntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIController:: |
|
WSEntityAPIController:: |
public | function |
WS Get's the entity Overrides EntityAPIController:: |
|
WSEntityAPIController:: |
public | function |
Implements EntityAPIControllerInterface. Overrides EntityAPIController:: |
|
WSEntityAPIController:: |
public | function |
Overridden. Overrides EntityAPIController:: |