summaryrefslogtreecommitdiff
path: root/modules/system/system.api.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/system/system.api.php')
-rw-r--r--modules/system/system.api.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index f428951e3..50521f5d8 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -284,6 +284,17 @@ function hook_entity_load($entities, $type) {
* The type of entity being inserted (i.e. node, user, comment).
*/
function hook_entity_insert($entity, $type) {
+ // Insert the new entity into a fictional table of all entities.
+ $info = entity_get_info($type);
+ $id = reset(entity_extract_ids($type, $entity));
+ db_insert('example_entity')
+ ->fields(array(
+ 'type' => $type,
+ 'id' => $id,
+ 'created' => REQUEST_TIME,
+ 'updated' => REQUEST_TIME,
+ ))
+ ->execute();
}
/**
@@ -295,6 +306,34 @@ function hook_entity_insert($entity, $type) {
* The type of entity being updated (i.e. node, user, comment).
*/
function hook_entity_update($entity, $type) {
+ // Update the entity's entry in a fictional table of all entities.
+ $info = entity_get_info($type);
+ $id = reset(entity_extract_ids($type, $entity));
+ db_update('example_entity')
+ ->fields(array(
+ 'updated' => REQUEST_TIME,
+ ))
+ ->condition('type', $type)
+ ->condition('id', $id)
+ ->execute();
+}
+
+/**
+ * Act on entities when deleted.
+ *
+ * @param $entity
+ * The entity object.
+ * @param $type
+ * The type of entity being deleted (i.e. node, user, comment).
+ */
+function hook_entity_delete($entity, $type) {
+ // Delete the entity's entry from a fictional table of all entities.
+ $info = entity_get_info($type);
+ $id = reset(entity_extract_ids($type, $entity));
+ db_delete('example_entity')
+ ->condition('type', $type)
+ ->condition('id', $id)
+ ->execute();
}
/**