You are here

public function WebformAdminConfigFormsForm::submitForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Form/AdminConfig/WebformAdminConfigFormsForm.php \Drupal\webform\Form\AdminConfig\WebformAdminConfigFormsForm::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 WebformAdminConfigBaseForm::submitForm

File

src/Form/AdminConfig/WebformAdminConfigFormsForm.php, line 691

Class

WebformAdminConfigFormsForm
Configure webform admin settings for forms.

Namespace

Drupal\webform\Form\AdminConfig

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $settings = $form_state
    ->getValue('page_settings') + $form_state
    ->getValue('form_settings') + $form_state
    ->getValue('form_behaviors') + $form_state
    ->getValue('wizard_settings') + $form_state
    ->getValue('preview_settings') + $form_state
    ->getValue('confirmation_settings') + $form_state
    ->getValue('share_settings') + $form_state
    ->getValue('ajax_settings') + $form_state
    ->getValue('bulk_form_settings') + $form_state
    ->getValue('dialog_settings');

  // Track if we need to trigger an update of all webform paths
  // because the 'default_page_base_path' changed.
  $update_paths = $settings['default_page_base_path'] !== $this
    ->config('webform.settings')
    ->get('settings.default_page_base_path') ? TRUE : FALSE;

  // Filter empty dialog options.
  foreach ($settings['dialog_options'] as $dialog_name => $dialog_options) {
    $settings['dialog_options'][$dialog_name] = array_filter($dialog_options);
  }

  // Update config and submit form.
  $config = $this
    ->config('webform.settings');
  $config
    ->set('settings', $settings + $config
    ->get('settings'));
  $config
    ->set('form', $form_state
    ->getValue('form') ?: []);
  $config
    ->set('third_party_settings', $form_state
    ->getValue('third_party_settings') ?: []);
  parent::submitForm($form, $form_state);

  /* Update paths */
  if ($update_paths) {

    /** @var \Drupal\webform\WebformInterface[] $webforms */
    $webforms = Webform::loadMultiple();
    foreach ($webforms as $webform) {
      $webform
        ->updatePaths();
    }
  }
}