public static function PaymentInformation::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/ Plugin/ Commerce/ CheckoutPane/ PaymentInformation.php, line 321
Class
- PaymentInformation
- Provides the payment information pane.
Namespace
Drupal\commerce_payment\Plugin\Commerce\CheckoutPaneCode
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();
$pane_input = NestedArray::getValue($user_input, $element['#parents']);
unset($pane_input['billing_information']);
unset($pane_input['add_payment_method']);
NestedArray::setValue($user_input, $element['#parents'], $pane_input);
}
return $element;
}