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, do not process input.
// @todo Refactor autocomplete.js to accept Drupal.settings instead of
// requiring extraneous markup.
$element['autocomplete'] = array(
'#type' => 'hidden',
'#input' => FALSE,
'#value' => url($element['#autocomplete_path'], array(
'absolute' => TRUE,
)),
'#disabled' => TRUE,
'#attributes' => array(
'class' => array(
'autocomplete',
),
'id' => $element['#id'] . '-autocomplete',
),
);
}
return $element;
}