You are here

public function GeshiFilterSettingsForm::submitForm in GeSHi Filter for syntax highlighting 8

Same name and namespace in other branches
  1. 8.2 src/Form/GeshiFilterSettingsForm.php \Drupal\geshifilter\Form\GeshiFilterSettingsForm::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 ConfigFormBase::submitForm

File

src/Form/GeshiFilterSettingsForm.php, line 266

Class

GeshiFilterSettingsForm
Form with the settings for the module.

Namespace

Drupal\geshifilter\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $errors = $form_state
    ->getErrors();
  if (count($errors) == 0) {
    $config = $this
      ->config('geshifilter.settings');
    $config
      ->set('use_format_specific_options', $form_state
      ->getValue('use_format_specific_options'))
      ->set('default_highlighting', $form_state
      ->getValue('default_highlighting'))
      ->set('default_line_numbering', $form_state
      ->getValue('default_line_numbering'))
      ->set('tab_width', $form_state
      ->getValue('tab_width'))
      ->set('use_highlight_string_for_php', $form_state
      ->getValue('use_highlight_string_for_php'))
      ->set('enable_keyword_urls', $form_state
      ->getValue('enable_keyword_urls'))
      ->set('css_mode', $form_state
      ->getValue('css_mode'))
      ->set('code_container', $form_state
      ->getValue('code_container'));

    // These values are not always set, so this prevents a warning.
    if ($form_state
      ->hasValue('tags')) {
      $config
        ->set('tags', $form_state
        ->getValue('tags'));
      $config
        ->set('tag_styles', $form_state
        ->getValue('tag_styles'));
      $config
        ->set('decode_entities', $form_state
        ->getValue('decode_entities'));
    }
    $config
      ->save();

    // Regenerate language css.
    if ($config
      ->get('css_mode') == GeshiFilter::CSS_CLASSES_AUTOMATIC) {
      GeshiFilterCss::generateLanguagesCssFile();
    }

    // Always clear the filter cache.
    Cache::invalidateTags([
      'geshifilter',
    ]);
    parent::submitForm($form, $form_state);
  }
}