public static function PaymentGatewayForm::processForm in Commerce Core 8.2
Builds the payment gateway form.
Parameters
array $element: The form element being processed.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $complete_form: The complete form structure.
Return value
array The processed form element.
Throws
\InvalidArgumentException Thrown when the #operation or #default_value properties are empty, or when the #default_value property is not a valid entity.
File
- modules/
payment/ src/ Element/ PaymentGatewayForm.php, line 72
Class
- PaymentGatewayForm
- Provides a form element for embedding the payment gateway forms.
Namespace
Drupal\commerce_payment\ElementCode
public static function processForm(array $element, FormStateInterface $form_state, array &$complete_form) {
if (empty($element['#operation'])) {
throw new \InvalidArgumentException('The commerce_payment_gateway_form element requires the #operation property.');
}
if (empty($element['#default_value'])) {
throw new \InvalidArgumentException('The commerce_payment_gateway_form element requires the #default_value property.');
}
elseif (isset($element['#default_value']) && !$element['#default_value'] instanceof EntityWithPaymentGatewayInterface) {
throw new \InvalidArgumentException('The commerce_payment_gateway_form #default_value property must be a payment or a payment method entity.');
}
/** @var \Drupal\commerce\InlineFormManager $inline_form_manager */
$inline_form_manager = \Drupal::service('plugin.manager.commerce_inline_form');
$inline_form = $inline_form_manager
->createInstance('payment_gateway_form', [
'operation' => $element['#operation'],
], $element['#default_value']);
$element['#inline_form'] = $inline_form;
$element = $inline_form
->buildInlineForm($element, $form_state);
// The updateValue() callback needs to run after the inline form ones.
$element['#commerce_element_submit'][] = [
get_called_class(),
'updateValue',
];
return $element;
}