You are here

public function Select2Widget::processFacetAutocomplete in Select 2 8

Set the autocomplete route properties.

Parameters

array $element: The render element.

Return value

array The render element with autocomplete settings.

File

modules/select2_facets/src/Plugin/facets/widget/Select2Widget.php, line 190

Class

Select2Widget
The select2 widget.

Namespace

Drupal\select2_facets\Plugin\facets\widget

Code

public function processFacetAutocomplete(array &$element) {
  $selection_settings = [
    'path' => $this->request
      ->getUri(),
    'match_operator' => $this
      ->getConfiguration()['match_operator'],
    'show_numbers' => $this
      ->getConfiguration()['show_numbers'],
  ];

  // Store the selection settings in the key/value store and pass a hashed key
  // in the route parameters.
  $data = serialize($selection_settings) . $this->facet
    ->getFacetSourceId() . $this->facet
    ->id();
  $selection_settings_key = Crypt::hmacBase64($data, Settings::getHashSalt());
  if (!$this->keyValueStore
    ->has($selection_settings_key)) {
    $this->keyValueStore
      ->set($selection_settings_key, $selection_settings);
  }
  $element['#autocomplete_route_name'] = 'select2_facets.facet_autocomplete';
  $element['#autocomplete_route_parameters'] = [
    'facetsource_id' => $this->facet
      ->getFacetSourceId(),
    'facet_id' => $this->facet
      ->id(),
    'selection_settings_key' => $selection_settings_key,
  ];
  return $element;
}