<?php
hook_ca_action()
?>Defines the available actions of the Conditional Actions module. Each condition has a title, description, category, a callback function, and a list of required arguments to that callback.
The callback function takes each entity listed in #arguments as an argument, plus a $settings array. The action settings come from the predicate that the action is attached to. When a predicate is created through the user interface, the settings come from the values entered into the actions form. Each action sees only its own settings. The actions form is built by a function named after the action's callback function. Add "_form" to the end of the callback function. The form is inserted directly into the predicate's actions form, so there isn't a form ID or validate and submit handlers automatically set for each action.
An array of actions, whose keys are the action IDs. Each action is an array with the following keys:
#title - The human-readable title.
#description - Helpful text describing the action.
#category - Used in optgroups when selecting a action from a list.
#callback - The callback function to perform the action. The action's settings form is this value plus "_form".
#arguments - An array of entity arguments. The keys of this array are used in the predicate #argument_map. The values are a small array of #entity and #title.
<?php
/**
* Implementation of hook_ca_action().
*/
function uc_order_ca_action() {
$order_arg = array(
'#entity' => 'uc_order',
'#title' => t('Order'),
);
$actions['uc_order_update_status'] = array(
'#title' => t('Update the order status'),
'#category' => t('Order'),
'#callback' => 'uc_order_action_update_status',
'#arguments' => array(
'order' => $order_arg,
),
);
$actions['uc_order_action_add_comment'] = array(
'#title' => t('Add a comment to the order'),
'#category' => t('Order'),
'#callback' => 'uc_order_action_add_comment',
'#arguments' => array(
'order' => $order_arg,
),
);
$actions['uc_order_email'] = array(
'#title' => t('Send an order email'),
'#category' => t('Order'),
'#callback' => 'uc_order_action_email',
'#arguments' => array(
'order' => $order_arg,
),
);
$actions['uc_order_email_invoice'] = array(
'#title' => t('Email an order invoice'),
'#category' => t('Order'),
'#callback' => 'uc_order_action_email_invoice',
'#arguments' => array(
'order' => $order_arg,
),
);
return
$actions;
}
// Update an order's status.
function uc_order_action_update_status(&$order, $settings) {
if (uc_order_update_status($order->order_id, $settings['order_status'])) {
$order->order_status = $settings['order_status'];
}
}
function
uc_order_action_update_status_form($form_state, $settings = array(), $arguments = array()) {
foreach (uc_order_status_list('general') as $status) {
$options[$status['id']] = $status['title'];
}
foreach (uc_order_status_list('specific') as $status) {
$options[$status['id']] = $status['title'];
}
$form['order_status'] = array(
'#type' => 'select',
'#title' => t('Order status'),
'#options' => $options,
'#default_value' => $settings['order_status'],
);
return
$form;
}
?>