You are here

public static function SynonymsEntityAutocomplete::elementSynonymsEntityAutocomplete in Synonyms 8

Form element process callback for 'synonyms_entity_autocomplete' type.

File

src/Element/SynonymsEntityAutocomplete.php, line 86

Class

SynonymsEntityAutocomplete
Form element for synonyms-friendly entity autocomplete.

Namespace

Drupal\synonyms\Element

Code

public static function elementSynonymsEntityAutocomplete(array &$element, FormStateInterface $form_state, array &$complete_form) {
  $data = [
    'target_type' => $element['#target_type'],
    'target_bundles' => $element['#target_bundles'],
    'suggestion_size' => $element['#suggestion_size'],
    'suggest_only_unique' => $element['#suggest_only_unique'],
    'match' => $element['#match'],
  ];
  $token = Crypt::hmacBase64(serialize($data), Settings::getHashSalt());
  $key_value_storage = \Drupal::keyValue('synonyms_entity_autocomplete');
  $key_value_storage
    ->setIfNotExists($token, $data);
  $element['#autocomplete_route_name'] = 'synonyms.entity_autocomplete';
  $element['#autocomplete_route_parameters'] = [
    'target_type' => $element['#target_type'],
    'token' => $token,
  ];
  return $element;
}