You are here

protected function PaymentMethodAddForm::buildPaymentMethodForm in Commerce Core 8.2

Builds the form for adding a payment method.

Parameters

array $form: The parent form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the complete form.

Return value

array The built form.

1 call to PaymentMethodAddForm::buildPaymentMethodForm()
PaymentMethodAddForm::buildForm in modules/payment/src/Form/PaymentMethodAddForm.php
Form constructor.

File

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

Class

PaymentMethodAddForm
Provides the payment method add form.

Namespace

Drupal\commerce_payment\Form

Code

protected function buildPaymentMethodForm(array $form, FormStateInterface $form_state) {
  $payment_method_storage = $this->entityTypeManager
    ->getStorage('commerce_payment_method');
  $payment_method = $payment_method_storage
    ->create([
    'type' => $form_state
      ->get('payment_method_type'),
    'payment_gateway' => $form_state
      ->get('payment_gateway'),
    'uid' => $form_state
      ->getBuildInfo()['args'][0]
      ->id(),
  ]);
  $inline_form = $this->inlineFormManager
    ->createInstance('payment_gateway_form', [
    'operation' => 'add-payment-method',
  ], $payment_method);
  $form['add_payment_method'] = [
    '#parents' => [
      'add_payment_method',
    ],
    '#inline_form' => $inline_form,
  ];
  $form['add_payment_method'] = $inline_form
    ->buildInlineForm($form['add_payment_method'], $form_state);
  return $form;
}