public function AutocompleteHelper::alterElement in Search API Autocomplete 8
Alters a textfield form element to use autocompletion.
Parameters
array $element: The altered element.
\Drupal\search_api_autocomplete\SearchInterface $search: The autocomplete search.
array $data: (optional) Additional data to pass to the autocomplete callback.
Overrides AutocompleteHelperInterface::alterElement
File
- src/
Utility/ AutocompleteHelper.php, line 52
Class
- AutocompleteHelper
- Provides helper methods for creating autocomplete suggestions.
Namespace
Drupal\search_api_autocomplete\UtilityCode
public function alterElement(array &$element, SearchInterface $search, array $data = []) {
$element['#type'] = 'search_api_autocomplete';
$element['#search_id'] = $search
->id();
$element['#additional_data'] = $data;
// In case another module (for instance, Better Exposed Filters) adds a
// "#process" key for our element type, make sure it is present on this
// element now, too.
$info = $this->elementInfo
->getInfo('search_api_autocomplete');
if (!empty($info['#process'])) {
$old_process = $element['#process'] ?? [];
$element['#process'] = array_merge($old_process, $info['#process']);
}
}