function example_form_example_search_form_alter in Search API Autocomplete 7
Implements hook_form_FORM_ID_alter().
Alters the example_search_form form to add autocompletion, if enabled by the user.
File
- ./
search_api_autocomplete.api.php, line 418 - Hooks provided by the Search API autocomplete module.
Code
function example_form_example_search_form_alter(array &$form, array &$form_state) {
// Compute the machine name that would be generated for this search in the
// 'list searches' callback.
$search_id = 'example_' . $form_state['search id'];
// Look up the corresponding autocompletion configuration, if it exists.
$search = search_api_autocomplete_search_load($search_id);
// Check whether autocompletion for the search is enabled.
// (This is also checked automatically later, so could be skipped here.)
if (!empty($search->enabled)) {
// If it is, pass the textfield for the search keywords to the
// alterElement() method of the search object.
$search
->alterElement($form['keys']);
}
}