You are here

function ca_conditions_form_remove_condition_group_submit in Ubercart 6.2

Submit handler for button to remove a condition grou.

See also

ca_conditions_form()

1 string reference to 'ca_conditions_form_remove_condition_group_submit'
_ca_conditions_form_tree in ca/ca.admin.inc
Recursively add logical groups to the conditions form as fieldsets.

File

ca/ca.admin.inc, line 872
Conditional actions overview UI.

Code

function ca_conditions_form_remove_condition_group_submit($form, &$form_state) {
  $group_key = FALSE;

  // Loop through the array keys of the conditions group.
  foreach (array_keys($form['conditions']['conditions']) as $key => $value) {

    // If we find the key we're looking for...
    if (is_numeric($value) && $value == $form_state['clicked_button']['#array_parents'][2]) {

      // Store its position as the new group key once the conditions are saved.
      // This is necessary because the save function will truncate any holes so
      // the keys are in numerical order starting with 0.
      $group_key = $key;
    }
  }

  // Save the existing conditions to preserve any changes.
  ca_conditions_form_update_conditions($form_state['values']['pid'], $form_state['values']['conditions']);

  // Fail if we didn't find a new group key for some reason.
  if ($group_key === FALSE) {
    drupal_set_message(t('An error occurred when trying to add the condition.  Please try again.'), 'error');
  }
  else {

    // Remove the condition group from the predicate.
    ca_remove_condition_group($form_state['values']['pid'], $group_key);

    // Display a confirmation message.
    drupal_set_message(t('Condition group removed.'));
  }
}