You are here

public function Checkout::submitConfigurationForm in Commerce PayPal 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\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().

Overrides PaymentGatewayBase::submitConfigurationForm

File

src/Plugin/Commerce/PaymentGateway/Checkout.php, line 349

Class

Checkout
Provides the PayPal Checkout payment gateway.

Namespace

Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::submitConfigurationForm($form, $form_state);
  if ($form_state
    ->getErrors()) {
    return;
  }
  $values = $form_state
    ->getValue($form['#parents']);
  $values['disable_funding'] = array_filter($values['disable_funding']);
  $values['disable_card'] = array_filter($values['disable_card']);
  $keys = [
    'payment_solution',
    'client_id',
    'secret',
    'intent',
    'disable_funding',
    'disable_card',
    'shipping_preference',
    'update_billing_profile',
    'update_shipping_profile',
    'enable_on_cart',
  ];

  // Only save the style settings if the customize buttons checkbox is checked.
  if (!empty($values['customize_buttons'])) {
    $keys[] = 'style';

    // Can't display the tagline if the layout configured is "vertical".
    if ($values['style']['layout'] === 'vertical') {
      $values['style']['tagline'] = FALSE;
    }
  }

  // When the "card" funding source is disabled, the "disable_card" setting
  // cannot be specified.
  if (isset($values['disable_funding']['card'])) {
    $values['disable_card'] = [];
  }
  foreach ($keys as $key) {
    if (!isset($values[$key])) {
      continue;
    }
    $this->configuration[$key] = $values[$key];
  }
}