Project

General

Profile

Revision dbb0c974

Added by Assos Assos about 10 years ago

Weekly update of contrib modules

View differences:

drupal7/sites/all/modules/commerce/modules/checkout/includes/commerce_checkout.pages.inc
90 90
    $form_errors = $form_state['storage']['errors'];
91 91
  }
92 92

  
93
  $form['#after_build'][] = 'commerce_checkout_form_process_errors';
94

  
93 95
  // Catch and clear already pushed messages.
94 96
  $previous_messages = drupal_get_messages();
95 97
  $show_errors_message = FALSE;
......
220 222
  return $form;
221 223
}
222 224

  
225
/**
226
 * After build callback for the checkout form.
227
 */
228
function commerce_checkout_form_process_errors($form, $form_state) {
229
  // Do this only on form rebuild (when the form will not be validated anymore):
230
  if (!empty($form_state['storage']['errors']) && !empty($form_state['rebuild'])) {
231
    foreach (array_keys($form_state['storage']['errors']) as $element_name) {
232
      // Look for all elements which have $element_name as parents, and
233
      // restore their #validated property (so _form_set_class() will set
234
      // the error class even though the rebuilt form is not validated).
235
      // We can't simply use drupal_array_get_nested_value(), since the #parents
236
      // property may have been changed and not match the form structure.
237
      _commerce_checkout_set_validated($form, $element_name);
238
    }
239
  }
240

  
241
  return $form;
242
}
243

  
244
/**
245
 * Set '#validated' on elements which have the specified parents.
246
 */
247
function _commerce_checkout_set_validated(&$element, $imploded_parents) {
248
  // Recurse to child elements if the current element is a container.
249
  foreach (element_children($element) as $key) {
250
    _commerce_checkout_set_validated($element[$key], $imploded_parents);
251
  }
252

  
253
  // This will also set #validated on all elements where #needs_validation would
254
  // be FALSE, but that doesn't hurt anything.
255
  if (!empty($element['#parents']) && strpos($imploded_parents, implode('][', $element['#parents'])) === 0) {
256
    $element['#validated'] = TRUE;
257
  }
258
}
259

  
223 260
/**
224 261
 * Validate handler for the continue button of the checkout form.
225 262
 *

Also available in: Unified diff