You are here

public function PaymentGatewayBase::buildConfigurationForm in Commerce Core 8.2

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PluginFormInterface::buildConfigurationForm

3 calls to PaymentGatewayBase::buildConfigurationForm()
Manual::buildConfigurationForm in modules/payment/src/Plugin/Commerce/PaymentGateway/Manual.php
Form constructor.
OffsiteRedirect::buildConfigurationForm in modules/payment_example/src/Plugin/Commerce/PaymentGateway/OffsiteRedirect.php
Form constructor.
OnsitePaymentGatewayBase::buildConfigurationForm in modules/payment/src/Plugin/Commerce/PaymentGateway/OnsitePaymentGatewayBase.php
Form constructor.
3 methods override PaymentGatewayBase::buildConfigurationForm()
Manual::buildConfigurationForm in modules/payment/src/Plugin/Commerce/PaymentGateway/Manual.php
Form constructor.
OffsiteRedirect::buildConfigurationForm in modules/payment_example/src/Plugin/Commerce/PaymentGateway/OffsiteRedirect.php
Form constructor.
OnsitePaymentGatewayBase::buildConfigurationForm in modules/payment/src/Plugin/Commerce/PaymentGateway/OnsitePaymentGatewayBase.php
Form constructor.

File

modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayBase.php, line 321

Class

PaymentGatewayBase
Provides the base class for payment gateways.

Namespace

Drupal\commerce_payment\Plugin\Commerce\PaymentGateway

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $modes = $this
    ->getSupportedModes();
  $payment_method_types = array_map(function ($payment_method_type) {
    return $payment_method_type
      ->getLabel();
  }, $this->paymentMethodTypes);
  $form['display_label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Display name'),
    '#description' => $this
      ->t('Shown to customers during checkout.'),
    '#default_value' => $this->configuration['display_label'],
    '#required' => TRUE,
  ];
  if (count($modes) > 1) {
    $form['mode'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Mode'),
      '#options' => $modes,
      '#default_value' => $this->configuration['mode'],
      '#required' => TRUE,
    ];
  }
  else {
    $mode_names = array_keys($modes);
    $form['mode'] = [
      '#type' => 'value',
      '#value' => reset($mode_names),
    ];
  }
  if (count($payment_method_types) > 1) {
    $form['payment_method_types'] = [
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Payment method types'),
      '#options' => $payment_method_types,
      '#default_value' => $this->configuration['payment_method_types'],
      '#required' => TRUE,
    ];
  }
  else {
    $form['payment_method_types'] = [
      '#type' => 'value',
      '#value' => $payment_method_types,
    ];
  }
  $form['collect_billing_information'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Collect billing information'),
    '#description' => $this
      ->t('Before disabling, make sure you are not legally required to collect billing information.'),
    '#default_value' => $this->configuration['collect_billing_information'],
    // Merchants can disable collecting billing information only if the
    // payment gateway indicated that it doesn't require it.
    '#access' => !$this->pluginDefinition['requires_billing_information'],
  ];
  return $form;
}