You are here

public function WebformResultsCustomForm::submitForm in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Form/WebformResultsCustomForm.php \Drupal\webform\Form\WebformResultsCustomForm::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/WebformResultsCustomForm.php, line 422

Class

WebformResultsCustomForm
Webform for webform results custom(ize) webform.

Namespace

Drupal\webform\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Set form value in webform state.
  $values = $form_state
    ->getValues();

  // Convert columns to simple array.
  $values['columns'] = array_values($values['columns']);

  // Convert limit to integer.
  $values['limit'] = (int) $values['limit'];

  // Remove default if source entity is defined.
  if (!empty($this->sourceEntity) || $this->type === 'user') {
    unset($values['default']);
  }
  foreach ($this->names as $name) {
    if (isset($values[$name])) {
      $this
        ->setData($name, $values[$name]);
    }
  }

  // Set results customize.
  if (isset($values['results_customize'])) {
    $this->webform
      ->setSetting('results_customize', $values['results_customize'])
      ->save();
  }

  // Display message.
  if ($this->customize) {
    if ($this->type === static::CUSTOMIZE_USER) {
      $this
        ->messenger()
        ->addStatus($this
        ->t('Your customized table has been saved.'));
    }
    else {
      $this
        ->messenger()
        ->addStatus($this
        ->t('The default customized table has been saved.'));
    }
  }
  else {
    $this
      ->messenger()
      ->addStatus($this
      ->t('The customized table has been saved.'));
  }

  // Set redirect.
  $redirect_url = $this->requestHandler
    ->getUrl($this->webform, $this->sourceEntity, 'webform.results_submissions');
  $form_state
    ->setRedirectUrl($redirect_url);
}