Implementation of hook_nodeapi().

File

modules/trigger/trigger.module, line 213
Enables functions to be stored and executed at a later time when triggered by other modules or by one of Drupal's core API hooks.

Code

function trigger_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {

  // Keep objects for reuse so that changes actions make to objects can persist.
  static $objects;

  // Prevent recursion by tracking which operations have already been called.
  static $recursion;

  // Support a subset of operations.
  if (!in_array($op, array(
    'view',
    'update',
    'presave',
    'insert',
    'delete',
  )) || isset($recursion[$op])) {
    return;
  }
  $recursion[$op] = TRUE;
  $aids = _trigger_get_hook_aids('nodeapi', $op);
  if (!$aids) {
    return;
  }
  $context = array(
    'hook' => 'nodeapi',
    'op' => $op,
  );

  // We need to get the expected object if the action's type is not 'node'.
  // We keep the object in $objects so we can reuse it if we have multiple actions
  // that make changes to an object.
  foreach ($aids as $aid => $action_info) {
    if ($action_info['type'] != 'node') {
      if (!isset($objects[$action_info['type']])) {
        $objects[$action_info['type']] = _trigger_normalize_node_context($action_info['type'], $node);
      }

      // Since we know about the node, we pass that info along to the action.
      $context['node'] = $node;
      $result = actions_do($aid, $objects[$action_info['type']], $context, $a3, $a4);
    }
    else {
      actions_do($aid, $node, $context, $a3, $a4);
    }
  }
}