_trigger_normalize_user_context

Versions
6 – 7
_trigger_normalize_user_context($type, $account)

Loads associated objects for user 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 user hook, the node object is not available since the user 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.

$account The account object that was passed via the user hook.

Return value

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

Code

modules/trigger/trigger.module, line 454

<?php
function _trigger_normalize_user_context($type, $account) {
  // Note that comment-type actions are not supported in user contexts,
  // because we wouldn't know which comment to choose.
  switch ($type) {
    // An action that works with nodes is being called in a user context.
    // If a single node is being viewed, return the node.
    case 'node':
      // If we are viewing an individual node, return the node.
      if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == NULL)) {
        return node_load(array('nid' => arg(1)));
      }
      break;
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.