You are here

function commerce_checkout_pane_settings_form_save_submit in Commerce Core 7

Submit handler for the checkout pane settings form's save button.

1 string reference to 'commerce_checkout_pane_settings_form_save_submit'
commerce_checkout_pane_settings_form in modules/checkout/includes/commerce_checkout.admin.inc
Build the configuration form for a checkout pane.

File

modules/checkout/includes/commerce_checkout.admin.inc, line 291
Administrative callbacks for the Checkout module.

Code

function commerce_checkout_pane_settings_form_save_submit($form, &$form_state) {

  // Load and update the pane with values from the form.
  $checkout_pane = commerce_checkout_pane_load($form_state['values']['checkout_pane']['pane_id']);

  // Update the fieldset collapsibility variables.
  switch ($form_state['values']['collapsibility']) {
    case 'collapsible':
      $checkout_pane['fieldset'] = TRUE;
      $checkout_pane['collapsible'] = TRUE;
      $checkout_pane['collapsed'] = FALSE;
      break;
    case 'collapsed':
      $checkout_pane['fieldset'] = TRUE;
      $checkout_pane['collapsible'] = TRUE;
      $checkout_pane['collapsed'] = TRUE;
      break;
    case 'none':
      $checkout_pane['fieldset'] = FALSE;
      $checkout_pane['collapsible'] = FALSE;
      $checkout_pane['collapsed'] = FALSE;
      break;
    case 'default':
    default:
      $checkout_pane['fieldset'] = TRUE;
      $checkout_pane['collapsible'] = FALSE;
      $checkout_pane['collapsed'] = FALSE;
      break;
  }

  // Update the pane's review page visibility.
  $checkout_pane['review'] = $form_state['values']['review'];

  // Save the changes.
  commerce_checkout_pane_save($checkout_pane);

  // Save this checkout pane's settings as if this was a system settings form.
  if (!empty($form['settings'])) {
    foreach (element_children($form['settings']) as $field) {
      if (!empty($form['settings'][$field]['#type'])) {

        // Provide support for containers one level deep.
        if (in_array($form['settings'][$field]['#type'], array(
          'container',
          'fieldset',
        ))) {
          foreach (element_children($form['settings'][$field]) as $nested_field) {
            if (isset($form_state['values'][$nested_field])) {
              variable_set($nested_field, $form_state['values'][$nested_field]);
            }
          }
        }
        elseif (isset($form_state['values'][$field])) {
          variable_set($field, $form_state['values'][$field]);
        }
      }
    }
  }
  drupal_set_message(t('Checkout pane saved.'));

  // Redirect to the main checkout form builder page on save.
  $form_state['redirect'] = 'admin/commerce/config/checkout/form';
}