1.20.x actions.inc actions_execute($action_name, Entity $entity = NULL, &$context)

Executes a single action.

Parameters

string $action_name: The machine name of the action to be executed.

Entity $entity: The entity object that the action will act upon, such as a node, user, or comment object.

Return value

The result of the executed action callback.:

Related topics

File

includes/actions.inc, line 86
This is the actions engine for executing stored actions.

Code

function actions_execute($action_name, Entity $entity = NULL, &$context) {
  // $stack tracks the number of recursive calls.
  static $stack;
  $stack++;
  $recursion_limit = config_get('system.core', 'action_recursion_limit');
  if (empty($recursion_limit)) {
    $recursion_limit = 35;
  }
  if ($stack > $recursion_limit) {
    watchdog('actions', 'Stack overflow: recursion limit for actions_execute() has been reached. Stack is limited by %limit calls.', array('%limit' => $recursion_limit), WATCHDOG_ERROR);
    return NULL;
  }

  $action_info = actions_get_info($action_name);
  $callback = $action_info['callback'];
  if (isset($action_info['file'])) {
    include_once BACKDROP_ROOT . '/' . backdrop_get_path('module', $action_info['module']) . '/' . $action_info['file'];
  }
  $context['action_name'] = $action_name;
  $context['action_info'] = $action_info;
  if (function_exists($callback)) {
    $result = $callback($entity, $context);
  }
  else {
    $result = NULL;
    trigger_error(t('The action "@action" could not be executed because the function "@callback" could not be found.', array('@action' => $action_name, '@callback' => $callback)), E_USER_ERROR);
  }

  $stack--;
  return $result;
}