You are here

function ca_load_trigger_actions in Ubercart 6.2

Return an array of actions available for the specified trigger.

Parameters

$trigger: The name of a trigger to find actions for; if left empty, the function returns conditions for the previously specified trigger.

Return value

A nested array of names/titles for the actions available for the trigger; in the format required by select elements in FAPI.

1 call to ca_load_trigger_actions()
ca_actions_form in ca/ca.admin.inc
Build a form for adding and editing actions on a predicate.

File

ca/ca.module, line 710
This is a demonstration module for the new conditional actions API.

Code

function ca_load_trigger_actions($trigger = '') {
  static $options = array();
  if (!empty($trigger)) {

    // Load the specified trigger.
    $trigger = ca_load_trigger($trigger);
    $trigger_entities = array();

    // Organize trigger arguments by entity.
    foreach ($trigger['#arguments'] as $argument) {
      $trigger_entities[$argument['#entity']] = $argument;
    }

    // Load and loop through all the actions defined by modules.
    $actions = ca_load_action();
    foreach ($actions as $name => $action) {

      // Check through each argument needed for the condition.
      foreach ($action['#arguments'] as $argument) {
        $entity = $argument['#entity'];

        // If the action requires an entity the trigger doesn't provide,
        // then skip to the next action.
        if ($entity != 'arguments' && !isset($trigger_entities[$entity])) {
          continue 2;
        }
      }

      // Getting this far means that all of the condition's arguments have
      // the same entity types as the trigger's. Add it to the options,
      // and group them by category for usability.
      $options[$action['#category']][$name] = $action['#title'];
    }

    // Alphabetically sort the groups and their options.
    foreach ($options as $group => $actions) {
      asort($actions);
      $options[$group] = $actions;
    }
    ksort($options);
  }
  return $options;
}