hook_ca_condition

Function hook_ca_condition() in ca.module:
<?php
  hook_ca_condition
()
?>

Description:

Defines the available conditions 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 condition settings come from the predicate that the condition is attached to. When a predicate is created through the user interface, the settings come from the values entered into the conditions form. Each condition sees only its own settings. The conditions form is built by a function named after the condition's callback function. Add "_form" to the end of the callback function. The form is inserted directly into the predicate's conditions form, so there isn't a form ID or validate and submit handlers automatically set for each condition.

Return value:

An array of conditions, whose keys are the condition IDs. Each condition is an array with the following keys:

  • #title - The human-readable title.
  • #description - Helpful text describing the condition.
  • #category - Used in optgroups when selecting a condition from a list.
  • #callback - The callback function to test the condition. The condition'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.

Example:
<?php
/**
* Implementation of hook_ca_condition().
*/
function uc_quote_ca_condition() {
  return array(
   
'uc_quote_condition_product_shipping_type' => array(
     
'#title' => t("Order has a product of a particular shipping type"),
     
'#category' => t('Order: Product'),
     
'#callback' => 'uc_quote_condition_product_shipping_type',
     
'#arguments' => array(
       
'order' => array('#entity' => 'uc_order', '#title' => t('Order')),
      ),
    ),
   
'uc_quote_condition_order_shipping_method' => array(
     
'#title' => t("Order has a shipping quote from a particular method"),
     
'#category' => t('Order: Shipping Quote'),
     
'#callback' => 'uc_quote_condition_order_shipping_method',
     
'#arguments' => array(
       
'order' => array('#entity' => 'uc_order', '#title' => t('Order')),
      ),
    ),
  );
}

/**
* Returns true if the order has a product of the chosen shipping type.
*
* @see uc_quote_condition_product_shipping_type_form()
*/
function uc_quote_condition_product_shipping_type($order, $settings) {
 
$result = FALSE;
  foreach (
$order->products as $product) {
    if (
$product->nid && uc_product_get_shipping_type($product) == $settings['type']) {
     
$result = TRUE;
      break;
    }
  }
  return
$result;
}

/**
* Settings form for uc_quote_condition_product_shipping_type().
*
* @ingroup forms
* @see uc_quote_condition_product_shipping_type()
* @see uc_quooe_condition_product_shipping_type_submit()
*/
function uc_quote_condition_product_shipping_type_form($form_state, $settings = array(), $arguments = array()) {
 
$form = array();

 

$options = array();
 
$types = uc_quote_get_shipping_types();
  foreach (
$types as $id => $type) {
   
$options[$id] = $type['title'];
  }
 
$form['type'] = array('#type' => 'select',
   
'#title' => t('Shipping type'),
   
'#options' => $options,
   
'#default_value' => $settings['type'],
  );

  return

$form;
}
?>