You are here

public static function PaymentMethodAddForm::clearValues in Commerce Core 8.2

Clears dependent form input when the payment_method changes.

Without this Drupal considers the rebuilt form to already be submitted, ignoring default values.

File

modules/payment/src/Form/PaymentMethodAddForm.php, line 248

Class

PaymentMethodAddForm
Provides the payment method add form.

Namespace

Drupal\commerce_payment\Form

Code

public static function clearValues(array $element, FormStateInterface $form_state) {
  $triggering_element = $form_state
    ->getTriggeringElement();
  if (!$triggering_element) {
    return $element;
  }
  $triggering_element_name = end($triggering_element['#parents']);
  if ($triggering_element_name == 'payment_method') {
    $user_input =& $form_state
      ->getUserInput();
    $form_input = NestedArray::getValue($user_input, $element['#parents']);
    unset($form_input['billing_information']);
    unset($form_input['add_payment_method']);
    NestedArray::setValue($user_input, $element['#parents'], $form_input);
  }
  return $element;
}