You are here

function ca_add_condition in Ubercart 6.2

Add a new condition to a predicate.

Parameters

$pid: The ID of the predicate to add the condition to.

$name: The name of the condition to add.

$group_key: The key of the condition group we're adding the condition to.

$mark_expanded: If set to TRUE marks the condition so that it will be expanded next time it displays in the UI so the user can adjust its settings.

Return value

An array representing the full, updated predicate.

1 call to ca_add_condition()
ca_conditions_form_add_condition_submit in ca/ca.admin.inc
Submit handler for button to add a condition to a condition group.

File

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

Code

function ca_add_condition($pid, $name, $group_key, $mark_expanded = TRUE) {

  // Load the predicate.
  $predicate = ca_load_predicate($pid);

  // Load the condition we want to add to the predicate.
  $data = ca_load_condition($name);

  // If the condition exists...
  if ($data) {

    // Build the condition array.
    $condition = array(
      '#name' => $name,
      '#title' => $data['#title'],
      '#argument_map' => array(),
      '#settings' => array(),
    );

    // Mark it for expansion in the form if specified.
    if ($mark_expanded) {
      $condition['#expanded'] = TRUE;
    }

    // Add the condition to the predicate.
    $predicate['#conditions']['#conditions'][$group_key]['#conditions'][] = $condition;
  }
  ca_save_predicate($predicate);
  return $predicate;
}