function trigger_comment

6.x trigger.module trigger_comment($a1, $op)

Implementation of hook_comment().

File

drupal-6.x/modules/trigger/trigger.module, line 280
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_comment($a1, $op) {
  // Keep objects for reuse so that changes actions make to objects can persist.
  static $objects;
  // We support a subset of operations.
  if (!in_array($op, array('insert', 'update', 'delete', 'view'))) {
    return;
  }
  $aids = _trigger_get_hook_aids('comment', $op);
  $context = array(
    'hook' => 'comment',
    'op' => $op,
  );
  // We need to get the expected object if the action's type is not 'comment'.
  // 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'] != 'comment') {
      if (!isset($objects[$action_info['type']])) {
        $objects[$action_info['type']] = _trigger_normalize_comment_context($action_info['type'], $a1);
      }
      // Since we know about the comment, we pass it along to the action
      // in case it wants to peek at it.
      $context['comment'] = (object) $a1;
      actions_do($aid, $objects[$action_info['type']], $context);
    }
    else {
      $comment = (object) $a1;
      actions_do($aid, $comment, $context);
    }
  }
}