You are here

public function ExpressCheckout::buildConfigurationForm in Commerce PayPal 8

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 PaymentGatewayBase::buildConfigurationForm

File

src/Plugin/Commerce/PaymentGateway/ExpressCheckout.php, line 120

Class

ExpressCheckout
Provides the Paypal Express Checkout payment gateway.

Namespace

Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);
  $form['api_username'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('API Username'),
    '#default_value' => $this->configuration['api_username'],
    '#required' => TRUE,
  ];
  $form['api_password'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('API Password'),
    '#default_value' => $this->configuration['api_password'],
    '#required' => TRUE,
  ];
  $form['signature'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Signature'),
    '#default_value' => $this->configuration['signature'],
    '#required' => TRUE,
  ];
  $form['solution_type'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Type of checkout flow'),
    '#description' => $this
      ->t('Express Checkout Account Optional (ECAO) where PayPal accounts are not required for payment may not be available in all markets.'),
    '#options' => [
      'Mark' => $this
        ->t('Require a PayPal account (this is the standard configuration).'),
      'SoleLogin' => $this
        ->t('Allow PayPal AND credit card payments, defaulting to the PayPal form.'),
      'SoleBilling' => $this
        ->t('Allow PayPal AND credit card payments, defaulting to the credit card form.'),
    ],
    '#default_value' => $this->configuration['solution_type'],
  ];
  $form['shipping_prompt'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Shipping address collection'),
    '#description' => $this
      ->t('Express Checkout will only request a shipping address if the Shipping module is enabled to store the address in the order.'),
    '#options' => [
      self::SHIPPING_SKIP => $this
        ->t('Do not ask for a shipping address at PayPal.'),
    ],
    '#default_value' => $this->configuration['shipping_prompt'],
  ];
  if ($this->moduleHandler
    ->moduleExists('commerce_shipping')) {
    $form['shipping_prompt']['#options'] += [
      self::SHIPPING_ASK_NOT_PRESENT => $this
        ->t('Ask for a shipping address at PayPal if the order does not have one yet.'),
      self::SHIPPING_ASK_ALWAYS => $this
        ->t('Ask for a shipping address at PayPal even if the order already has one.'),
    ];
  }
  return $form;
}