You are here

public function WebformVariantViewForm::submitForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Form/WebformVariantViewForm.php \Drupal\webform\Form\WebformVariantViewForm::submitForm()

Form submission handler.

Parameters

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

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

Overrides FormInterface::submitForm

File

src/Form/WebformVariantViewForm.php, line 126

Class

WebformVariantViewForm
Provides a view and tests form for webform variants.

Namespace

Drupal\webform\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $variants = $form_state
    ->getValue('variants');

  // Build query string.
  $query = [];
  $element_keys = $this->webform
    ->getElementsVariant();
  foreach ($element_keys as $element_key) {
    if (empty($variants[$element_key])) {
      continue;
    }
    $variant_id = $variants[$element_key];
    $variant_element = $this->webform
      ->getElement($element_key);

    // If #prepopulate is disabled use '_webform_variant'
    // querystring parameter for view and test operations.
    // @see \Drupal\webform\Entity\Webform::getSubmissionForm
    if (empty($variant_element['#prepopulate'])) {
      $query += [
        '_webform_variant' => [],
      ];
      $query['_webform_variant'][$element_key] = $variant_id;
    }
    else {
      $query[$element_key] = $variant_id;
    }
  }
  $options = [
    'query' => $query,
  ];
  $rel = $form['#rel'];
  $redirect_url = $this->webform
    ->toUrl($rel, $options);
  $form_state
    ->setRedirectUrl($redirect_url);
}