You are here

public function Search404Settings::submitForm in Search 404 8

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

Class

Search404Settings
Configure settings for search404.

Namespace

Drupal\search404\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $settings = $this
    ->configFactory()
    ->getEditable('search404.settings');
  $settings
    ->set('search404_redirect_301', $form_state
    ->getValue('search404_redirect_301'))
    ->set('search404_do_google_cse', $form_state
    ->getValue('search404_do_google_cse'))
    ->set('search404_do_search_by_page', $form_state
    ->getValue('search404_do_search_by_page'))
    ->set('search404_first', $form_state
    ->getValue('search404_first'))
    ->set('search404_first_on_paths', $form_state
    ->getValue('search404_first_on_paths'))
    ->set('search404_jump', $form_state
    ->getValue('search404_jump'))
    ->set('search404_use_or', $form_state
    ->getValue('search404_use_or'))
    ->set('search404_ignore', $form_state
    ->getValue('search404_ignore'))
    ->set('search404_ignore_paths', $form_state
    ->getValue('search404_ignore_paths'))
    ->set('search404_ignore_query', $form_state
    ->getValue('search404_ignore_query'))
    ->set('search404_ignore_extensions', $form_state
    ->getValue('search404_ignore_extensions'))
    ->set('search404_page_text', $form_state
    ->getValue('search404_page_text'))
    ->set('search404_page_title', $form_state
    ->getValue('search404_page_title'))
    ->set('search404_regex', $form_state
    ->getValue('search404_regex'))
    ->set('search404_skip_auto_search', $form_state
    ->getValue('search404_skip_auto_search'))
    ->set('search404_use_search_engine', $form_state
    ->getValue('search404_use_search_engine'))
    ->set('search404_disable_error_message', $form_state
    ->getValue('search404_disable_error_message'))
    ->set('search404_custom_error_message', $form_state
    ->getValue('search404_custom_error_message'))
    ->set('search404_page_redirect', $form_state
    ->getValue('search404_page_redirect'));

  // Save custom path if the corresponding checkbox is checked.
  if (!empty($form_state
    ->getValue('search404_do_custom_search'))) {
    $settings
      ->set('search404_custom_search_path', $form_state
      ->getValue('search404_custom_search_path'));
    $settings
      ->set('search404_do_custom_search', $form_state
      ->getValue('search404_do_custom_search'));
  }
  else {
    $settings
      ->set('search404_custom_search_path', '');
    $settings
      ->set('search404_do_custom_search', 0);
  }

  // Save all configurations.
  $settings
    ->save();
  parent::submitForm($form, $form_state);
}