You are here

protected function WebformSubmissionForm::wizardSubmit in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/WebformSubmissionForm.php \Drupal\webform\WebformSubmissionForm::wizardSubmit()

Webform submission handler for the wizard submit action.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

3 calls to WebformSubmissionForm::wizardSubmit()
WebformSubmissionForm::gotoPage in src/WebformSubmissionForm.php
Webform submission handler for the 'goto' action.
WebformSubmissionForm::next in src/WebformSubmissionForm.php
Webform submission handler for the 'next' action.
WebformSubmissionForm::previous in src/WebformSubmissionForm.php
Webform submission handler for the 'previous' action.

File

src/WebformSubmissionForm.php, line 1616

Class

WebformSubmissionForm
Provides a webform to collect and edit submissions.

Namespace

Drupal\webform

Code

protected function wizardSubmit(array &$form, FormStateInterface $form_state) {
  $current_page = $form_state
    ->get('current_page');
  if ($current_page === WebformInterface::PAGE_CONFIRMATION) {
    $this
      ->complete($form, $form_state);
    $this
      ->submitForm($form, $form_state);
    $this
      ->save($form, $form_state);
    $this
      ->confirmForm($form, $form_state);
  }
  elseif ($this
    ->draftEnabled() && $this
    ->getWebformSetting('draft_auto_save') && !$this->entity
    ->isCompleted()) {
    $form_state
      ->set('in_draft', TRUE);
    $this
      ->submitForm($form, $form_state);
    $this
      ->save($form, $form_state);
    $this
      ->rebuild($form, $form_state);
  }
  else {
    $this
      ->submitForm($form, $form_state);
    $this
      ->rebuild($form, $form_state);
  }

  // Announce current page with progress.
  // @see template_preprocess_webform_progress()
  if ($this
    ->isAjax()) {
    $pages = $this
      ->getPages($form, $form_state);

    // Make sure the current page exists because the confirmation page
    // may not be included in the wizard's pages.
    if (isset($pages[$current_page])) {
      $page_keys = array_keys($pages);
      $page_indexes = array_flip($page_keys);
      $total_pages = count($page_keys);
      $current_index = $page_indexes[$current_page];
      $t_args = [
        '@title' => $this
          ->getWebform()
          ->label(),
        '@page' => $pages[$current_page]['#title'],
        '@start' => $current_index + 1,
        '@end' => $total_pages,
      ];
      $this
        ->announce($this
        ->t('"@title: @page" loaded. (@start of @end)', $t_args));
    }
  }
}