You are here

public function CheckoutFlowWithPanesBase::submitConfigurationForm in Commerce Core 8.2

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 CheckoutFlowBase::submitConfigurationForm

File

modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowWithPanesBase.php, line 493

Class

CheckoutFlowWithPanesBase
Provides a base checkout flow that uses checkout panes.

Namespace

Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::submitConfigurationForm($form, $form_state);
  $panes = $form_state
    ->get('panes');

  // If the main "Save" button was submitted while a pane configuration
  // subform was being edited, update the configuration as if the subform's
  // "Update" button had been submitted.
  if ($pane_id = $form_state
    ->get('pane_configuration_edit')) {
    $parents = [
      'panes',
      $pane_id,
      'configuration',
    ];
    $pane_configuration_form = NestedArray::getValue($form, $parents);

    /** @var \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneInterface[] $panes */
    $pane =& $panes[$pane_id];
    $pane
      ->submitConfigurationForm($pane_configuration_form, $form_state);
  }
  $form_values = $form_state
    ->getValue($form['#parents']);
  foreach ($form_values['panes'] as $pane_id => $pane_values) {
    $pane = $panes[$pane_id];

    // If the pane was disabled, reset its configuration.
    if ($pane_values['step_id'] == '_disabled') {
      $pane
        ->setConfiguration([]);
    }

    // Transfer the step and weight changes from the form.
    $pane
      ->setStepId($pane_values['step_id']);
    $pane
      ->setWeight($pane_values['weight']);
  }

  // Store the pane configuration.
  $this->configuration['panes'] = [];
  foreach ($panes as $pane_id => $pane) {
    $this->configuration['panes'][$pane_id] = $pane
      ->getConfiguration();
  }
}