View source
<?php
function hook_post_action_entity_insert($entity, $type) {
$entity_info = array(
'entity' => $entity,
'type' => $type,
'operation' => 'insert',
);
drupal_register_shutdown_function('_hook_post_action_post_save', $entity_info);
}
function hook_post_action_entity_update($entity, $type) {
$original = isset($entity->original) ? $entity->original : NULL;
$entity_info = array(
'entity' => $entity,
'type' => $type,
'operation' => 'update',
'original' => $original,
);
drupal_register_shutdown_function('_hook_post_action_post_save', $entity_info);
}
function hook_post_action_entity_delete($entity, $type) {
$entity_info = array(
'entity' => $entity,
'type' => $type,
'operation' => 'delete',
);
drupal_register_shutdown_function('_hook_post_action_post_save', $entity_info);
}
function _hook_post_action_post_save($entity_info) {
$entity = $entity_info['entity'];
$type = $entity_info['type'];
$op = $entity_info['operation'];
$original = array_key_exists('original', $entity_info) ? $entity_info['original'] : NULL;
$entity_is_saved = FALSE;
$new_entity = NULL;
if ($original != NULL) {
$entity->original = $original;
}
if ($op == 'insert' || $op == 'update') {
$entity_is_saved = TRUE;
}
if ($op == 'delete') {
list($id) = entity_extract_ids($type, $entity);
$new_entity = entity_load($type, array(
$id,
));
if (!$new_entity) {
$entity_is_saved = TRUE;
}
}
if ($entity_is_saved) {
module_invoke_all('entity_post' . $op, $entity, $type);
module_invoke_all('entity_postsave', $entity, $type, $op);
if ($type == 'node') {
module_invoke_all('node_post' . $op, $entity);
module_invoke_all('node_postsave', $entity, $op);
}
}
}