function _trigger_normalize_comment_context

Loads associated objects for comment triggers.

When an action is called in a context that does not match its type, the object that the action expects must be retrieved. For example, when an action that works on nodes is called during the comment hook, the node object is not available since the comment hook doesn't pass it. So here we load the object the action expects.

Parameters

$type: The type of action that is about to be called.

$comment: The comment that was passed via the comment hook.

Return value

The object expected by the action that is about to be called.

1 call to _trigger_normalize_comment_context()
_trigger_comment in drupal/modules/trigger/trigger.module
Calls action functions for comment triggers.

File

drupal/modules/trigger/trigger.module, line 361
Enables functions to be stored and executed at a later time.

Code

function _trigger_normalize_comment_context($type, $comment) {
  switch ($type) {

    // An action that works with nodes is being called in a comment context.
    case 'node':
      return node_load(is_array($comment) ? $comment['nid'] : $comment->nid);

    // An action that works on users is being called in a comment context.
    case 'user':
      return user_load(is_array($comment) ? $comment['uid'] : $comment->uid);
  }
}