Commit e577cff7 authored by Dries's avatar Dries

- Patch #1309394 by effulgentsia, sun: process #autocomplete_path() for all...

- Patch #1309394 by effulgentsia, sun: process #autocomplete_path() for all form elements; remove custom/duplicated code from theme_textfield().
parent 642f91d1
...@@ -3702,6 +3702,36 @@ function theme_vertical_tabs($variables) { ...@@ -3702,6 +3702,36 @@ function theme_vertical_tabs($variables) {
return $output; return $output;
} }
/**
* Adds autocomplete functionality to elements with a valid #autocomplete_path.
*
* @param $element
* The form element to process. Properties used:
* - #autocomplete_path: A system path to be used as callback URL by the
* autocomplete JavaScript library.
*/
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;
}
/** /**
* Returns HTML for a submit button form element. * Returns HTML for a submit button form element.
* *
...@@ -3792,7 +3822,7 @@ function theme_hidden($variables) { ...@@ -3792,7 +3822,7 @@ function theme_hidden($variables) {
* An associative array containing: * An associative array containing:
* - element: An associative array containing the properties of the element. * - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #description, #size, #maxlength, * Properties used: #title, #value, #description, #size, #maxlength,
* #placeholder, #required, #attributes, #autocomplete_path. * #placeholder, #required, #attributes.
* *
* @ingroup themeable * @ingroup themeable
*/ */
...@@ -3802,23 +3832,7 @@ function theme_textfield($variables) { ...@@ -3802,23 +3832,7 @@ function theme_textfield($variables) {
element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder')); element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder'));
_form_set_class($element, array('form-text')); _form_set_class($element, array('form-text'));
$extra = ''; return '<input' . drupal_attributes($element['#attributes']) . ' />' . drupal_render_children($element);
if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
drupal_add_library('system', 'drupal.autocomplete');
$element['#attributes']['class'][] = 'form-autocomplete';
$attributes = array();
$attributes['type'] = 'hidden';
$attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
$attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE));
$attributes['disabled'] = 'disabled';
$attributes['class'][] = 'autocomplete';
$extra = '<input' . drupal_attributes($attributes) . ' />';
}
$output = '<input' . drupal_attributes($element['#attributes']) . ' />';
return $output . $extra;
} }
/** /**
...@@ -3828,7 +3842,7 @@ function theme_textfield($variables) { ...@@ -3828,7 +3842,7 @@ function theme_textfield($variables) {
* An associative array containing: * An associative array containing:
* - element: An associative array containing the properties of the element. * - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #description, #size, #maxlength, * Properties used: #title, #value, #description, #size, #maxlength,
* #placeholder, #required, #attributes, #autocomplete_path. * #placeholder, #required, #attributes.
* *
* @ingroup themeable * @ingroup themeable
*/ */
...@@ -3838,23 +3852,7 @@ function theme_email($variables) { ...@@ -3838,23 +3852,7 @@ function theme_email($variables) {
element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder')); element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder'));
_form_set_class($element, array('form-email')); _form_set_class($element, array('form-email'));
$extra = ''; return '<input' . drupal_attributes($element['#attributes']) . ' />' . drupal_render_children($element);
if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
drupal_add_library('system', 'drupal.autocomplete');
$element['#attributes']['class'][] = 'form-autocomplete';
$attributes = array();
$attributes['type'] = 'hidden';
$attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
$attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE));
$attributes['disabled'] = 'disabled';
$attributes['class'][] = 'autocomplete';
$extra = '<input' . drupal_attributes($attributes) . ' />';
}
$output = '<input' . drupal_attributes($element['#attributes']) . ' />';
return $output . $extra;
} }
/** /**
...@@ -3878,7 +3876,7 @@ function form_validate_email(&$element, &$form_state) { ...@@ -3878,7 +3876,7 @@ function form_validate_email(&$element, &$form_state) {
* An associative array containing: * An associative array containing:
* - element: An associative array containing the properties of the element. * - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #description, #size, #maxlength, * Properties used: #title, #value, #description, #size, #maxlength,
* #placeholder, #required, #attributes, #autocomplete_path. * #placeholder, #required, #attributes.
* *
* @ingroup themeable * @ingroup themeable
*/ */
...@@ -3888,23 +3886,7 @@ function theme_tel($variables) { ...@@ -3888,23 +3886,7 @@ function theme_tel($variables) {
element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder')); element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder'));
_form_set_class($element, array('form-tel')); _form_set_class($element, array('form-tel'));
$extra = ''; return '<input' . drupal_attributes($element['#attributes']) . ' />' . drupal_render_children($element);
if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
drupal_add_library('system', 'drupal.autocomplete');
$element['#attributes']['class'][] = 'form-autocomplete';
$attributes = array();
$attributes['type'] = 'hidden';
$attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
$attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE));
$attributes['disabled'] = 'disabled';
$attributes['class'][] = 'autocomplete';
$extra = '<input' . drupal_attributes($attributes) . ' />';
}
$output = '<input' . drupal_attributes($element['#attributes']) . ' />';
return $output . $extra;
} }
/** /**
...@@ -3914,7 +3896,7 @@ function theme_tel($variables) { ...@@ -3914,7 +3896,7 @@ function theme_tel($variables) {
* An associative array containing: * An associative array containing:
* - element: An associative array containing the properties of the element. * - element: An associative array containing the properties of the element.
* Properties used: #title, #value, #description, #size, #maxlength, * Properties used: #title, #value, #description, #size, #maxlength,
* #placeholder, #required, #attributes, #autocomplete_path. * #placeholder, #required, #attributes.
* *
* @ingroup themeable * @ingroup themeable
*/ */
...@@ -3924,23 +3906,7 @@ function theme_url($variables) { ...@@ -3924,23 +3906,7 @@ function theme_url($variables) {
element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder')); element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder'));
_form_set_class($element, array('form-url')); _form_set_class($element, array('form-url'));
$extra = ''; return '<input' . drupal_attributes($element['#attributes']) . ' />' . drupal_render_children($element);
if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
drupal_add_library('system', 'drupal.autocomplete');
$element['#attributes']['class'][] = 'form-autocomplete';
$attributes = array();
$attributes['type'] = 'hidden';
$attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
$attributes['value'] = url($element['#autocomplete_path'], array('absolute' => TRUE));
$attributes['disabled'] = 'disabled';
$attributes['class'][] = 'autocomplete';
$extra = '<input' . drupal_attributes($attributes) . ' />';
}
$output = '<input' . drupal_attributes($element['#attributes']) . ' />';
return $output . $extra;
} }
/** /**
......
...@@ -361,7 +361,7 @@ function system_element_info() { ...@@ -361,7 +361,7 @@ function system_element_info() {
'#size' => 60, '#size' => 60,
'#maxlength' => 128, '#maxlength' => 128,
'#autocomplete_path' => FALSE, '#autocomplete_path' => FALSE,
'#process' => array('ajax_process_form'), '#process' => array('form_process_autocomplete', 'ajax_process_form'),
'#theme' => 'textfield', '#theme' => 'textfield',
'#theme_wrappers' => array('form_element'), '#theme_wrappers' => array('form_element'),
); );
...@@ -370,7 +370,7 @@ function system_element_info() { ...@@ -370,7 +370,7 @@ function system_element_info() {
'#size' => 30, '#size' => 30,
'#maxlength' => 128, '#maxlength' => 128,
'#autocomplete_path' => FALSE, '#autocomplete_path' => FALSE,
'#process' => array('ajax_process_form'), '#process' => array('form_process_autocomplete', 'ajax_process_form'),
'#theme' => 'tel', '#theme' => 'tel',
'#theme_wrappers' => array('form_element'), '#theme_wrappers' => array('form_element'),
); );
...@@ -379,7 +379,7 @@ function system_element_info() { ...@@ -379,7 +379,7 @@ function system_element_info() {
'#size' => 60, '#size' => 60,
'#maxlength' => EMAIL_MAX_LENGTH, '#maxlength' => EMAIL_MAX_LENGTH,
'#autocomplete_path' => FALSE, '#autocomplete_path' => FALSE,
'#process' => array('ajax_process_form'), '#process' => array('form_process_autocomplete', 'ajax_process_form'),
'#element_validate' => array('form_validate_email'), '#element_validate' => array('form_validate_email'),
'#theme' => 'email', '#theme' => 'email',
'#theme_wrappers' => array('form_element'), '#theme_wrappers' => array('form_element'),
...@@ -389,7 +389,7 @@ function system_element_info() { ...@@ -389,7 +389,7 @@ function system_element_info() {
'#size' => 60, '#size' => 60,
'#maxlength' => 255, '#maxlength' => 255,
'#autocomplete_path' => FALSE, '#autocomplete_path' => FALSE,
'#process' => array('ajax_process_form'), '#process' => array('form_process_autocomplete', 'ajax_process_form'),
'#element_validate' => array('form_validate_url'), '#element_validate' => array('form_validate_url'),
'#theme' => 'url', '#theme' => 'url',
'#theme_wrappers' => array('form_element'), '#theme_wrappers' => array('form_element'),
...@@ -410,7 +410,7 @@ function system_element_info() { ...@@ -410,7 +410,7 @@ function system_element_info() {
'#maxlength' => 64, '#maxlength' => 64,
'#size' => 60, '#size' => 60,
'#autocomplete_path' => FALSE, '#autocomplete_path' => FALSE,
'#process' => array('form_process_machine_name', 'ajax_process_form'), '#process' => array('form_process_machine_name', 'form_process_autocomplete', 'ajax_process_form'),
'#element_validate' => array('form_validate_machine_name'), '#element_validate' => array('form_validate_machine_name'),
'#theme' => 'textfield', '#theme' => 'textfield',
'#theme_wrappers' => array('form_element'), '#theme_wrappers' => array('form_element'),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment