function ca_perform_actions in Ubercart 6.2
Perform a predicate's actions in order, preserving changes to the arguments.
Parameters
$predicate: A fully loaded predicate array.
$arguments: The array of parsed arguments for the trigger.
Return value
An array of results, if any, that were returned by the actions.
1 call to ca_perform_actions()
- ca_pull_trigger in ca/
ca.module - Pull a trigger and evaluate any predicates associated with that trigger.
File
- ca/
ca.module, line 459 - This is a demonstration module for the new conditional actions API.
Code
function ca_perform_actions($predicate, $arguments) {
// Exit now if we don't have any actions.
if (count($predicate['#actions']) == 0) {
return;
}
$results = array();
// Load the data for the actions as defined by modules.
$action_data = module_invoke_all('ca_action');
foreach ($predicate['#actions'] as $i => $action) {
$args = array();
// Get the callback function for the current action.
$callback = $action_data[$action['#name']]['#callback'];
// Do not perform the action if the function does not exist.
if (!function_exists($callback)) {
continue;
}
// Loop through the expected arguments for an action.
foreach ($action_data[$action['#name']]['#arguments'] as $key => $value) {
// Using the argument map for the action on this predicate, fetch the
// argument that was passed to the trigger that matches to the argument
// needed to perform this action.
if (isset($action['#argument_map'][$key])) {
// Adding the arguments as references so action functions can update the
// arguments here when they make changes to the argument data.
if ($value['#entity'] == 'arguments') {
$args[] =& $arguments;
}
else {
$args[] =& $arguments[$action['#argument_map'][$key]]['#data'];
}
}
else {
// Skip this action of the predicate didn't map the arguments needed.
continue 2;
}
}
// Add the condition settings to the argument list.
$args[] = isset($action['#settings']) && is_array($action['#settings']) ? $action['#settings'] : array();
// Call the action's function with the appropriate arguments.
$results[$i] = call_user_func_array($callback, $args);
}
return $results;
}