You are here

public static function CheckoutFlowWithPanesBase::multistepSubmit in Commerce Core 8.2

Form submission handler for multistep buttons.

Parameters

array $form: The parent form.

\Drupal\Core\Form\FormStateInterface $form_state: The complete form state.

File

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

Class

CheckoutFlowWithPanesBase
Provides a base checkout flow that uses checkout panes.

Namespace

Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow

Code

public static function multistepSubmit(array $form, FormStateInterface $form_state) {
  $triggering_element = $form_state
    ->getTriggeringElement();
  switch ($triggering_element['#op']) {
    case 'edit':

      // Open the configuration form.
      $form_state
        ->set('pane_configuration_edit', $triggering_element['#pane_id']);
      break;
    case 'update':
      $form_state
        ->set('pane_configuration_edit', NULL);

      // Submit the pane configuration form and update the pane in form state.
      $pane_id = $triggering_element['#pane_id'];
      $parents = array_slice($triggering_element['#parents'], 0, -2);
      $pane_configuration_form = NestedArray::getValue($form, $parents);

      /** @var \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneInterface[] $panes */
      $panes = $form_state
        ->get('panes');
      $pane =& $panes[$pane_id];
      $pane
        ->submitConfigurationForm($pane_configuration_form, $form_state);
      $form_state
        ->set('panes', $panes);
      break;
    case 'cancel':

      // Close the configuration form.
      $form_state
        ->set('pane_configuration_edit', NULL);
      break;
  }
  $form_state
    ->setRebuild();
}