You are here

public function DisableMessagesSettingsForm::submitForm in Disable Messages 8

Same name and namespace in other branches
  1. 2.x src/Form/DisableMessagesSettingsForm.php \Drupal\disable_messages\Form\DisableMessagesSettingsForm::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/DisableMessagesSettingsForm.php, line 24

Class

DisableMessagesSettingsForm
Provides a form for administering disable messages.

Namespace

Drupal\disable_messages\Form

Code

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

  // Process and save the regular expressions in another variable.
  $patterns = explode("\n", $form_state
    ->getValue('disable_messages_ignore_patterns'));
  $regexps = [];
  $disable_messages_ignore_case = $this
    ->config('disable_messages.settings')
    ->get('disable_messages_ignore_case');
  $ignore_case = $disable_messages_ignore_case == '1' ? 'i' : '';
  foreach ($patterns as $pattern) {
    $pattern = preg_replace([
      '/^\\s*/',
      '/\\s*$/',
    ], '', $pattern);
    $pattern = '/^' . $pattern . '$/' . $ignore_case;
    $regexps[] = $pattern;
  }
  $this
    ->config('disable_messages.settings')
    ->set('disable_messages_enable', $form_state
    ->getValue('disable_messages_enable'))
    ->set('disable_messages_exclude_users', $form_state
    ->getValue('disable_messages_exclude_users'))
    ->set('disable_messages_filter_by_page', $form_state
    ->getValue('disable_messages_filter_by_page'))
    ->set('disable_messages_page_filter_paths', $form_state
    ->getValue('disable_messages_page_filter_paths'))
    ->set('disable_messages_ignore_patterns', $form_state
    ->getValue('disable_messages_ignore_patterns'))
    ->set('disable_messages_ignore_regex', $regexps)
    ->set('disable_messages_enable_debug', $form_state
    ->getValue('disable_messages_enable_debug'))
    ->set('disable_messages_ignore_case', $form_state
    ->getValue('disable_messages_ignore_case'))
    ->set('disable_messages_debug_visible_div', $form_state
    ->getValue('disable_messages_debug_visible_div'))
    ->save();
  parent::submitForm($form, $form_state);
}