public static function PaymentAddForm::clearValue in Commerce Core 8.2
Clears the payment method value when the payment gateway changes.
Changing the payment gateway results in a new set of payment methods, causing the submitted value to trigger an "Illegal choice" error, cause it's no longer allowed. Clearing the value causes the element to fallback to the default value, avoiding the error.
File
- modules/
payment/ src/ Form/ PaymentAddForm.php, line 223
Class
- PaymentAddForm
- Provides the payment add form.
Namespace
Drupal\commerce_payment\FormCode
public static function clearValue(array $element, FormStateInterface $form_state) {
$value = $element['#value'];
if (!isset($element['#options'][$value])) {
$element['#value'] = NULL;
$user_input =& $form_state
->getUserInput();
unset($user_input['payment_option']);
}
return $element;
}