You are here

public function PaymentGatewayForm::buildInlineForm in Commerce Core 8.2

Builds the inline form.

Parameters

array $inline_form: The inline form, containing the following basic properties:

  • #parents: Identifies the location of the field values in $form_state.

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

Return value

array The built inline form.

Overrides InlineFormBase::buildInlineForm

File

modules/payment/src/Plugin/Commerce/InlineForm/PaymentGatewayForm.php, line 98

Class

PaymentGatewayForm
Provides a form element for embedding payment gateway forms.

Namespace

Drupal\commerce_payment\Plugin\Commerce\InlineForm

Code

public function buildInlineForm(array $inline_form, FormStateInterface $form_state) {
  $inline_form = parent::buildInlineForm($inline_form, $form_state);
  assert($this->entity instanceof EntityWithPaymentGatewayInterface);
  $plugin = $this->entity
    ->getPaymentGateway()
    ->getPlugin();
  $this->pluginForm = $this->pluginFormFactory
    ->createInstance($plugin, $this->configuration['operation']);
  assert($this->pluginForm instanceof PaymentGatewayFormInterface);
  $this->pluginForm
    ->setEntity($this->entity);
  try {
    $inline_form = $this->pluginForm
      ->buildConfigurationForm($inline_form, $form_state);
  } catch (PaymentGatewayException $e) {
    if (empty($this->configuration['catch_build_exceptions'])) {
      throw $e;
    }
    $inline_form['error'] = [
      '#markup' => $this
        ->t('An error occurred while contacting the gateway. Please try again later.'),
    ];
    $inline_form['#process'][] = [
      get_class($this),
      'preventSubmit',
    ];
  }
  return $inline_form;
}