You are here

public function SuggestionEditForm::submitForm in Autocomplete Search Suggestions 8.2

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

AJAX callback for the indexing 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/SuggestionEditForm.php, line 102

Class

SuggestionEditForm
Suggestion indexing form.

Namespace

Drupal\suggestion\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $src = 0;
  foreach ((array) $form_state
    ->getValue('src') as $bit) {
    $src |= intval($bit);
  }
  $key = [
    'ngram' => $form_state
      ->getValue('ngram'),
  ];
  $fields = [
    'atoms' => $form_state
      ->getValue('atoms'),
    'density' => Helper::calculateDensity($src, $form_state
      ->getValue('atoms'), $form_state
      ->getValue('qty')),
    'qty' => $form_state
      ->getValue('qty'),
    'src' => $src,
  ];
  Storage::mergeSuggestion($key, $fields);
  $this
    ->messenger()
    ->addStatus($this
    ->t('Updated: “@ngram”', [
    '@ngram' => $form_state
      ->getValue('ngram'),
  ]));
}