You are here

public function TwoCheckout::buildConfigurationForm in Ubercart 8.4

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

File

payment/uc_2checkout/src/Plugin/Ubercart/PaymentMethod/TwoCheckout.php, line 60

Class

TwoCheckout
Defines the 2Checkout payment method.

Namespace

Drupal\uc_2checkout\Plugin\Ubercart\PaymentMethod

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form['sid'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Vendor account number'),
    '#description' => $this
      ->t('Your 2Checkout vendor account number.'),
    '#default_value' => $this->configuration['sid'],
    '#size' => 16,
  ];
  $form['secret_word'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Secret word for order verification'),
    '#description' => $this
      ->t('The secret word entered in your 2Checkout account Look and Feel settings.'),
    '#default_value' => $this->configuration['secret_word'],
    '#size' => 16,
  ];
  $form['demo'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable demo mode, allowing you to process fake orders for testing purposes.'),
    '#default_value' => $this->configuration['demo'],
  ];
  $form['language'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Language preference'),
    '#description' => $this
      ->t('Adjust language on 2Checkout pages.'),
    '#options' => [
      'en' => $this
        ->t('English'),
      'sp' => $this
        ->t('Spanish'),
    ],
    '#default_value' => $this->configuration['language'],
  ];
  $form['check'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow customers to choose to pay by credit card or online check.'),
    '#default_value' => $this->configuration['check'],
  ];
  $form['checkout_type'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Checkout type'),
    '#options' => [
      'dynamic' => $this
        ->t('Dynamic checkout (user is redirected to 2CO)'),
      'direct' => $this
        ->t('Direct checkout (payment page opens in iframe popup)'),
    ],
    '#default_value' => $this->configuration['checkout_type'],
  ];
  $form['notification_url'] = [
    '#type' => 'url',
    '#title' => $this
      ->t('Instant notification settings URL'),
    '#description' => $this
      ->t('Pass this URL to the <a href=":help_url">instant notification settings</a> parameter in your 2Checkout account. This way, any refunds or failed fraud reviews will automatically cancel the Ubercart order.', [
      ':help_url' => Url::fromUri('https://www.2checkout.com/static/va/documentation/INS/index.html')
        ->toString(),
    ]),
    '#default_value' => Url::fromRoute('uc_2checkout.notification', [], [
      'absolute' => TRUE,
    ])
      ->toString(),
    '#attributes' => [
      'readonly' => 'readonly',
    ],
  ];
  return $form;
}