Adds autocomplete functionality to elements with a valid #autocomplete_path.
Suppose your autocomplete path in the menu system is 'mymodule_autocomplete.' In your form you have:
'#autocomplete_path' => 'mymodule_autocomplete/' . $some_key . '/' . $some_id,
The user types in "keywords" so the full path called is: 'mymodule_autocomplete/$some_key/$some_id?q=keywords'
$element: The form element to process. Properties used:
function form_process_autocomplete($element, &$form_state) {
if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) {
$element['#attributes']['class'][] = 'form-autocomplete';
$element['#attached']['library'][] = array(
'system',
'drupal.autocomplete',
);
// Provide a hidden element for the JavaScript behavior to bind to. Since
// this element is for client-side functionality only, and we don't want to
// collect any input from it, use #theme='hidden' instead of #type='hidden'.
// @todo Refactor autocomplete.js to accept Drupal.settings instead of
// requiring extraneous markup.
$element['autocomplete'] = array(
'#theme' => 'hidden',
'#attributes' => array(
'id' => $element['#id'] . '-autocomplete',
'value' => url($element['#autocomplete_path'], array(
'absolute' => TRUE,
)),
'class' => array(
'autocomplete',
),
'disabled' => 'disabled',
),
);
}
return $element;
}