You are here

protected function SuggestionAdminForm::setAutocomplete in Autocomplete Search Suggestions 8

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

Build an autocomplete form ID to field name hash.

Parameters

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

1 call to SuggestionAdminForm::setAutocomplete()
SuggestionAdminForm::submitForm in src/Form/SuggestionAdminForm.php
Submit function for the suggestion configuration form.

File

src/Form/SuggestionAdminForm.php, line 281

Class

SuggestionAdminForm
Suggestion configuration form.

Namespace

Drupal\suggestion\Form

Code

protected function setAutocomplete(FormStateInterface $form_state) {
  $hash = [];
  if ($form_state
    ->getValue('entry_style') == 'simple') {
    $hash[trim($form_state
      ->getValue('form_key'))] = trim($form_state
      ->getValue('field_name'));
  }
  else {
    foreach (preg_split('/\\s*[\\n\\r]+\\s*/s', trim($form_state
      ->getValue('autocomplete'))) as $line) {
      if (preg_match('/^\\W*([a-z_0-9]+)\\W+([a-z_0-9]+)\\W*$/', $line, $m)) {
        $hash[$m[1]] = $m[2];
      }
    }
    ksort($hash);
  }
  SuggestionHelper::setConfig('autocomplete', $hash);
}