You are here

function commerce_fedex_settings_form_submit in Commerce FedEx 7

Submit handler for FedEx admin settings form.

Parameters

array $form: The FedEx admin settings form.

array $form_state: The FedEx admin settings form state.

File

includes/commerce_fedex.admin.inc, line 389
Admin functions for Commerce FedEx.

Code

function commerce_fedex_settings_form_submit($form, $form_state) {

  // Check the FedEx service variable before the form is saved to check if this
  // value has been changed in this form submit.
  $services = variable_get('commerce_fedex_services', NULL);

  // Make sure State/Province value is saved as uppercase.
  if (!empty($form_state['values']['commerce_fedex_state'])) {
    $form_state['values']['commerce_fedex_state'] = drupal_strtoupper($form_state['values']['commerce_fedex_state']);
  }

  // Loop through each of the settings fields and save their values.
  foreach (commerce_fedex_settings_fields() as $key) {
    if (!empty($form_state['values'][$key])) {
      variable_set($key, $form_state['values'][$key]);
    }
    else {

      // If the value is not set then delete the variable instead of saving
      // a NULL value (unless it's the FedEx password which is only set when
      // it is updated).
      if (!in_array($key, array(
        'commerce_fedex_password',
        'commerce_fedex_password_testing',
      ))) {
        variable_del($key);
      }
    }
  }

  // If the selected shipping services have changed with this form submit then
  // clear the shipping services, rules, and menu caches.
  if ($services !== $form_state['values']['commerce_fedex_services']) {
    commerce_shipping_services_reset();
    entity_defaults_rebuild();
    rules_clear_cache(TRUE);
    menu_rebuild();
  }
  drupal_set_message(t('The FedEx configuration options have been saved.'));
}