Skip to content

Commit 5c60575

Browse files
committed
Handling also search_api autocomplete.
1 parent 2f69f29 commit 5c60575

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

modules/elasticsearch_connector_search_api/elasticsearch_connector_search_api.module

+32
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,38 @@ function elasticsearch_connector_search_api_module_implements_alter(&$implementa
266266
if ($hook == 'form_views_exposed_form_alter') {
267267
unset($implementations['search_api_autocomplete']);
268268
}
269+
elseif ($hook == 'form_search_api_page_search_form') {
270+
unset($implementations['search_api_autocomplete']);
271+
}
272+
}
273+
274+
/**
275+
* Implements hook_form_FORM_ID_alter().
276+
*
277+
* Adds autocompletion to the keywords field on search pages, if enabled by the
278+
* user.
279+
*/
280+
function elasticsearch_connector_search_api_form_search_api_page_search_form_alter(array &$form, array &$form_state) {
281+
if (isset($form['form'])) {
282+
$form = &$form['form'];
283+
}
284+
$id = 'search_api_page_' . $form['id']['#value'];
285+
$search = search_api_autocomplete_search_load($id);
286+
if ($search && $search->enabled) {
287+
$include_js = FALSE;
288+
$search->alterElement($form['keys_' . $form['id']['#value']]);
289+
if (!empty($search->options['custom']['link_suggestions'])) {
290+
$form['keys_' . $form['id']['#value']]['#attributes'] = array(
291+
'class' => array('elasticsearch-autocomplete')
292+
);
293+
$include_js = TRUE;
294+
}
295+
296+
if ($include_js) {
297+
$form['#attached']['js'][] =
298+
drupal_get_path('module', 'elasticsearch_connector_search_api') . '/js/elasticsearch_connector_search_api_autocomplete.js';
299+
}
300+
}
269301
}
270302

271303
/**

0 commit comments

Comments
 (0)