function _trigger_normalize_comment_context

_trigger_normalize_comment_context($type, $comment)

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.

File

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);
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!trigger!trigger.module/function/_trigger_normalize_comment_context/7.x