You are here

function commerce_checkout_builder_form_validate in Commerce Core 7

Validation handler for the checkout builder form.

File

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

Code

function commerce_checkout_builder_form_validate(&$form, &$form_state) {
  $pages = commerce_checkout_pages();

  // Get unmodified checkout panes.
  $panes = commerce_checkout_panes(array(), TRUE);

  // Get saved checkout panes. If an error is detected, we'll need it to
  // reference the original form structure so we can accurately locate the
  // elements in the form and set their values.
  $saved_panes = commerce_checkout_panes();

  // Loop through each configured panes.
  foreach ($form_state['values']['panes'] as $pane_id => $checkout_pane) {

    // Check if pane should be locked but is configured on the wrong checkout page.
    if (!empty($panes[$pane_id]['locked']) && $checkout_pane['page'] != $panes[$pane_id]['page']) {
      $element =& $form['page'][$saved_panes[$pane_id]['page']]['panes'][$pane_id]['page'];
      if ($panes[$pane_id]['page'] == 'disabled') {
        drupal_set_message(t('%pane must be configured before it can be enabled. It has been moved back to a disabled position.', array(
          '%pane' => $panes[$pane_id]['title'],
        )), 'warning');
      }
      else {
        drupal_set_message(t('%pane is locked in the code to the %page page and was repositioned accordingly.', array(
          '%pane' => $panes[$pane_id]['title'],
          '%page' => $pages[$panes[$pane_id]['page']]['name'],
        )), 'warning');
      }
      form_set_value($element, $panes[$pane_id]['page'], $form_state);
    }
  }
}