You are here

public function SuggestionAdminForm::submitForm in Autocomplete Search Suggestions 8

Same name and namespace in other branches
  1. 8.2 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 156

Class

SuggestionAdminForm
Suggestion configuration form.

Namespace

Drupal\suggestion\Form

Code

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

  // Set synced to false if any indexing fields change.
  if ($current->atoms_max != $form_state
    ->getValue('atoms_max')) {
    $this
      ->setSynced(FALSE);
  }
  elseif ($current->atoms_min != $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.
  SuggestionHelper::setConfig('atoms_max', $form_state
    ->getValue('atoms_max'));
  SuggestionHelper::setConfig('atoms_min', $form_state
    ->getValue('atoms_min'));
  SuggestionHelper::setConfig('entry_style', $form_state
    ->getValue('entry_style'));
  SuggestionHelper::setConfig('limit', $form_state
    ->getValue('limit'));
  SuggestionHelper::setConfig('max', $form_state
    ->getValue('max'));
  SuggestionHelper::setConfig('min', $form_state
    ->getValue('min'));
  SuggestionHelper::setConfig('field_name', trim($form_state
    ->getValue('field_name')));
  SuggestionHelper::setConfig('form_key', trim($form_state
    ->getValue('form_key')));
  SuggestionHelper::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);
}