You are here

function _hook_post_action_post_save in Hook Post Action 7

Same name and namespace in other branches
  1. 8 hook_post_action.module \_hook_post_action_post_save()

Parameters

$entity:

$type:

$op:

3 string references to '_hook_post_action_post_save'
hook_post_action_entity_delete in ./hook_post_action.module
hook_post_action_entity_insert in ./hook_post_action.module
hook_post_action_entity_update in ./hook_post_action.module

File

./hook_post_action.module, line 52

Code

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 is not null then restore it to the original property in the entity.
  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);
    }
  }
}