You are here

public function SuggestionAdminForm::submitForm in Autocomplete Search Suggestions 8.2

Same name and namespace in other branches
  1. 8 src/Form/SuggestionAdminForm.php \Drupal\suggestion\Form\SuggestionAdminForm::submitForm()
  2. 3.0.x src/Form/SuggestionAdminForm.php \Drupal\suggestion\Form\SuggestionAdminForm::submitForm()

Submit function for the suggestion configuration form.

Parameters

array $form: A drupal form array.

Drupal\Core\Form\FormStateInterface $form_state: A Drupal form state object.

Overrides FormInterface::submitForm

File

src/Form/SuggestionAdminForm.php, line 184

Class

SuggestionAdminForm
Suggestion configuration form.

Namespace

Drupal\suggestion\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $current = Helper::getConfig();

  // Set synced to false if any indexing fields change.
  if ($current->atoms_max != $form_state
    ->getValue('atoms_max')) {
    $this
      ->setSynced(FALSE);
  }
  if ($current->atoms_max != $form_state
    ->getValue('atoms_min')) {
    $this
      ->setSynced(FALSE);
  }
  elseif ($current->limit != $form_state
    ->getValue('limit')) {
    $this
      ->setSynced(FALSE);
  }
  elseif ($current->max != $form_state
    ->getValue('max')) {
    $this
      ->setSynced(FALSE);
  }
  elseif ($current->min != $form_state
    ->getValue('min')) {
    $this
      ->setSynced(FALSE);
  }
  elseif ($current->types != $form_state
    ->getValue('types')) {
    $this
      ->setSynced(FALSE);
  }

  // Set config fields.
  Helper::setConfig('atoms_max', $form_state
    ->getValue('atoms_max'));
  Helper::setConfig('atoms_min', $form_state
    ->getValue('atoms_min'));
  Helper::setConfig('entry_style', $form_state
    ->getValue('entry_style'));
  Helper::setConfig('limit', $form_state
    ->getValue('limit'));
  Helper::setConfig('max', $form_state
    ->getValue('max'));
  Helper::setConfig('min', $form_state
    ->getValue('min'));
  Helper::setConfig('field_name', trim($form_state
    ->getValue('field_name')));
  Helper::setConfig('form_key', trim($form_state
    ->getValue('form_key')));
  Helper::setConfig('types', $form_state
    ->getValue('types'));

  // Form ID to field name hash.
  $this
    ->setAutocomplete($form_state);

  // Priority suggestions.
  $this
    ->setKeywords($form_state);

  // Stopwords.
  $this
    ->setStopwords($form_state);
}