You are here

public function YamlFormAdminSettingsForm::submitForm in YAML Form 8

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 ConfigFormBase::submitForm

File

src/Form/YamlFormAdminSettingsForm.php, line 678

Class

YamlFormAdminSettingsForm
Configure form admin settings for this site.

Namespace

Drupal\yamlform\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $settings = $form_state
    ->getValue('page') + $form_state
    ->getValue('form') + $form_state
    ->getValue('wizard') + $form_state
    ->getValue('preview') + $form_state
    ->getValue('draft') + $form_state
    ->getValue('confirmation') + $form_state
    ->getValue('limit');

  // Trigger update all form paths if the 'default_page_base_path' changed.
  $update_paths = $settings['default_page_base_path'] != $this
    ->config('yamlform.settings')
    ->get('settings.default_page_base_path') ? TRUE : FALSE;
  $config = $this
    ->config('yamlform.settings');

  // Convert list of included types to excluded types.
  $excluded_types = array_diff($this->elementTypes, array_filter($form_state
    ->getValue('excluded_types')));
  ksort($excluded_types);
  $config
    ->set('settings', $settings);
  $config
    ->set('elements', $form_state
    ->getValue('elements') + [
    'excluded_types' => $excluded_types,
  ]);
  $config
    ->set('file', $form_state
    ->getValue('file'));
  $config
    ->set('format', array_filter($form_state
    ->getValue('format')));
  $config
    ->set('mail', $form_state
    ->getValue('mail'));
  $config
    ->set('export', $this->submissionExporter
    ->getValuesFromInput($form_state
    ->getValues()));
  $config
    ->set('batch', $form_state
    ->getValue('batch'));
  $config
    ->set('test', $form_state
    ->getValue('test'));
  $config
    ->set('ui', $form_state
    ->getValue('ui'));
  $config
    ->set('library', $form_state
    ->getValue('library'));
  $config
    ->save();
  if ($update_paths) {

    /** @var \Drupal\yamlform\YamlFormInterface[] $yamlforms */
    $yamlforms = YamlForm::loadMultiple();
    foreach ($yamlforms as $yamlform) {
      $yamlform
        ->updatePaths();
    }
  }
  parent::submitForm($form, $form_state);
}