You are here

public function Mollie::buildConfigurationForm in Commerce Mollie 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/Mollie.php, line 93

Class

Mollie
Provides the Mollie payment gateway.

Namespace

Drupal\commerce_mollie\Plugin\Commerce\PaymentGateway

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildConfigurationForm($form, $form_state);

  /*
   * Set a warning message when the default order-type workflow does not have
   * a validation step.
   */

  /** @var \Drupal\commerce_order\Entity\OrderType $order_type */
  $order_workflow = Drupal::config('commerce_order.commerce_order_type.default')
    ->get('workflow');
  if (strpos($order_workflow, 'validation') === FALSE) {
    $link = Link::fromTextAndUrl($this
      ->t('Configure Order Types workflow'), Url::fromRoute('entity.commerce_order_type.collection'))
      ->toString();
    Drupal::messenger()
      ->addWarning($this
      ->t('It is recommended to configure a workflow with a Validation step. @link', [
      '@link' => $link,
    ]));
  }

  // Build the form.
  $host = Drupal::request()
    ->getHost();
  $form['api_key_test'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Mollie Test API-key'),
    '#default_value' => $this->configuration['api_key_test'],
    '#required' => TRUE,
  ];
  $form['api_key_live'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Mollie Live API-key'),
    '#default_value' => $this->configuration['api_key_live'],
    '#required' => TRUE,
  ];
  $form['callback_domain'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Callback domain'),
    '#description' => $this
      ->t('Callback domain that Mollie must use to post transaction results to.<br/>
      <ul>
        <li>Do not add an "/" after .com</li>
        <li>You must include https:// or http://</li>
        <li>The domain must be reachable for the Mollie servers, otherwise payments are not processed.</li>
      </ul>
      For live websites this is the your live domain</br><br/>

      If left empty the domain visible in the browser window will be used.<br/>
      Currently that is: @host<br/><br/>

      While developing you can use a tunneled domain that hits your local development machine.<br/>
      This can be done with https://localtunnel.github.io/www<br/>
      <code>lt --port 80 --local-host @host</code>
      ', [
      '@host' => $host,
    ]),
    '#default_value' => $this->configuration['callback_domain'],
    '#required' => FALSE,
  ];
  return $form;
}