function ca_predicate_meta_form_submit in Ubercart 6.2
See also
File
- ca/
ca.admin.inc, line 242 - Conditional actions overview UI.
Code
function ca_predicate_meta_form_submit($form, &$form_state) {
$form_state['redirect'] = CA_UI_PATH;
$save = FALSE;
// Load the original predicate, if any.
$predicate = array();
if ($form_state['values']['predicate_pid'] !== 0) {
$predicate = ca_load_predicate($form_state['values']['predicate_pid']);
$predicate['#pid'] = $form_state['values']['predicate_pid'];
}
// Setup a list of fields to check for and apply changes.
$fields = array(
'title',
'trigger',
'description',
'class',
'status',
'weight',
);
// Compare the values from the form submission with what is already set.
foreach ($fields as $field) {
if (!isset($predicate['#' . $field]) || $form_state['values']['predicate_' . $field] != $predicate['#' . $field]) {
$predicate['#' . $field] = $form_state['values']['predicate_' . $field];
$save = TRUE;
}
}
// Add empty conditions and actions arrays if this is a new predicate.
if (empty($predicate['#pid'])) {
$predicate['#pid'] = variable_get('ca_predicates_pid', 1);
variable_set('ca_predicates_pid', $predicate['#pid'] + 1);
$predicate['#conditions'] = array();
$predicate['#actions'] = array();
// For new predicates, redirect to the conditions tab.
$form_state['redirect'] = CA_UI_PATH . '/' . $predicate['#pid'] . '/edit/conditions';
}
// Check to see if any changes were made and save if necessary.
if ($save) {
ca_save_predicate($predicate);
}
drupal_set_message(t('Predicate meta data saved.'));
}