Commit 91bc8bed authored by webchick's avatar webchick

#709892 by drunken monkey, Yorirou: Complete entity CRUD hook invocations: Add...

#709892 by drunken monkey, Yorirou: Complete entity CRUD hook invocations: Add a hook_entity_delete() for consistency.
parent 8ab93aea
......@@ -1190,6 +1190,7 @@ function file_delete(stdClass $file, $force = FALSE) {
// Let other modules clean up any references to the deleted file.
module_invoke_all('file_delete', $file);
module_invoke_all('entity_delete', $file, 'file');
// Make sure the file is deleted before removing its row from the
// database, so UIs can still find the file in the database.
......
......@@ -1592,6 +1592,7 @@ function comment_delete_multiple($cids) {
foreach ($comments as $comment) {
field_attach_delete('comment', $comment);
module_invoke_all('comment_delete', $comment);
module_invoke_all('entity_delete', $comment, 'comment');
// Delete the comment's replies.
$child_cids = db_query('SELECT cid FROM {comment} WHERE pid = :cid', array(':cid' => $comment->cid))->fetchCol();
......
......@@ -1171,6 +1171,7 @@ function node_delete_multiple($nids) {
// Call the node-specific callback (if any):
node_invoke($node, 'delete');
module_invoke_all('node_delete', $node);
module_invoke_all('entity_delete', $node, 'node');
field_attach_delete('node', $node);
// Remove this node from the search index if needed.
......
......@@ -19,6 +19,7 @@ files[] = tests/bootstrap.test
files[] = tests/cache.test
files[] = tests/common.test
files[] = tests/database_test.test
files[] = tests/entity_crud_hook_test.test
files[] = tests/entity_query.test
files[] = tests/error.test
files[] = tests/file.test
......
; $Id$
name = "Entity CRUD Hooks Test"
description = "Support module for CRUD hook tests."
core = 7.x
package = Testing
files[] = entity_crud_hook_test.module
version = VERSION
hidden = TRUE
<?php
// $Id$
//
// Insert hooks
//
/**
* Implements hook_entity_insert().
*/
function entity_crud_hook_test_entity_insert($entity, $type) {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $type);
}
/**
* Implements hook_comment_insert().
*/
function entity_crud_hook_test_comment_insert() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_file_insert().
*/
function entity_crud_hook_test_file_insert() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_node_insert().
*/
function entity_crud_hook_test_node_insert() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_taxonomy_term_insert().
*/
function entity_crud_hook_test_taxonomy_term_insert() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_taxonomy_vocabulary_insert().
*/
function entity_crud_hook_test_taxonomy_vocabulary_insert() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_user_insert().
*/
function entity_crud_hook_test_user_insert() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
//
// Load hooks
//
/**
* Implements hook_entity_load().
*/
function entity_crud_hook_test_entity_load(array $entities, $type) {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $type);
}
/**
* Implements hook_comment_load().
*/
function entity_crud_hook_test_comment_load() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_file_load().
*/
function entity_crud_hook_test_file_load() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_node_load().
*/
function entity_crud_hook_test_node_load() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_taxonomy_term_load().
*/
function entity_crud_hook_test_taxonomy_term_load() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_taxonomy_vocabulary_load().
*/
function entity_crud_hook_test_taxonomy_vocabulary_load() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_user_load().
*/
function entity_crud_hook_test_user_load() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
//
// Update hooks
//
/**
* Implements hook_entity_update().
*/
function entity_crud_hook_test_entity_update($entity, $type) {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $type);
}
/**
* Implements hook_comment_update().
*/
function entity_crud_hook_test_comment_update() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_file_update().
*/
function entity_crud_hook_test_file_update() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_node_update().
*/
function entity_crud_hook_test_node_update() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_taxonomy_term_update().
*/
function entity_crud_hook_test_taxonomy_term_update() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_taxonomy_vocabulary_update().
*/
function entity_crud_hook_test_taxonomy_vocabulary_update() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_user_update().
*/
function entity_crud_hook_test_user_update() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
//
// Delete hooks
//
/**
* Implements hook_entity_delete().
*/
function entity_crud_hook_test_entity_delete($entity, $type) {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $type);
}
/**
* Implements hook_comment_delete().
*/
function entity_crud_hook_test_comment_delete() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_file_delete().
*/
function entity_crud_hook_test_file_delete() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_node_delete().
*/
function entity_crud_hook_test_node_delete() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_taxonomy_term_delete().
*/
function entity_crud_hook_test_taxonomy_term_delete() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_taxonomy_vocabulary_delete().
*/
function entity_crud_hook_test_taxonomy_vocabulary_delete() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
/**
* Implements hook_user_delete().
*/
function entity_crud_hook_test_user_delete() {
$_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
}
This diff is collapsed.
......@@ -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();
}
/**
......
......@@ -431,7 +431,8 @@ function taxonomy_vocabulary_delete($vid) {
->execute();
field_attach_delete_bundle('taxonomy_term', $vocabulary['machine_name']);
module_invoke_all('taxonomy', 'delete', 'vocabulary', $vocabulary);
module_invoke_all('taxonomy_vocabulary_delete', $vocabulary);
module_invoke_all('entity_delete', $vocabulary, 'taxonomy_vocabulary');
cache_clear_all();
entity_get_controller('taxonomy_vocabulary')->resetCache();
......@@ -612,6 +613,7 @@ function taxonomy_term_delete($tid) {
field_attach_delete('taxonomy_term', $term);
module_invoke_all('taxonomy_term_delete', $term);
module_invoke_all('entity_delete', $term, 'taxonomy_term');
taxonomy_terms_static_reset();
}
}
......
......@@ -2345,6 +2345,7 @@ function user_delete_multiple(array $uids) {
foreach ($accounts as $uid => $account) {
module_invoke_all('user_delete', $account);
module_invoke_all('entity_delete', $account, 'user');
field_attach_delete('user', $account);
drupal_session_destroy_uid($account->uid);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment