diff --git a/core/includes/form.inc b/core/includes/form.inc index 0ef70f8..4971885 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2893,22 +2893,21 @@ function theme_details($variables) { } /** - * Returns HTML for a radio button form element. + * Prepares an element to be rendered as a checkbox. + * + * @param array $element + * An associative array containing the properties of the element. + * Properties used: #required, #return_value, #value, #attributes, #title, + * #description * * Note: The input "name" attribute needs to be sanitized before output, which * is currently done by initializing Drupal\Core\Template\Attribute with * all the attributes. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #required, #return_value, #value, #attributes, #title, - * #description - * - * @ingroup themeable + * @return + * The modified element with checkbox attributes. */ -function theme_radio($variables) { - $element = $variables['element']; +function form_pre_render_radio($element) { $element['#attributes']['type'] = 'radio'; element_set_attributes($element, array('id', 'name', '#return_value' => 'value')); @@ -2917,7 +2916,7 @@ function theme_radio($variables) { } _form_set_attributes($element, array('form-radio')); - return ''; + return $element; } /** @@ -3164,19 +3163,17 @@ function form_process_radios($element) { } /** - * Returns HTML for a checkbox form element. + * Prepares an element to be rendered as a checkbox. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #title, #value, #return_value, #description, #required, * #attributes, #checked. * - * @ingroup themeable + * @return + * The modified element with checkbox attributes. */ -function theme_checkbox($variables) { - $element = $variables['element']; - $t = get_t(); +function form_pre_render_checkbox($element) { $element['#attributes']['type'] = 'checkbox'; element_set_attributes($element, array('id', 'name', '#return_value' => 'value')); @@ -3186,7 +3183,7 @@ function theme_checkbox($variables) { } _form_set_attributes($element, array('form-checkbox')); - return ''; + return $element; } /** @@ -4087,34 +4084,49 @@ function form_process_autocomplete($element, &$form_state) { } /** - * Returns HTML for a submit button form element. + * Preprocesses variables for input form elements. * - * @param $variables + * @param array $variables * An associative array containing: * - element: An associative array containing the properties of the element. - * Properties used: #attributes, #button_type, #name, #value. * * @ingroup themeable */ -function theme_submit($variables) { - return theme('button', $variables['element']); +function template_preprocess_input(&$variables) { + $element = $variables['element']; + $variables['attributes'] = new Attribute($element['#attributes']); } /** - * Returns HTML for a button form element. + * Returns HTML for an input form element. * - * @param $variables + * @param array $variables * An associative array containing: * - element: An associative array containing the properties of the element. + * Properties used: #attributes. + * + * @ingroup themeable + */ +function theme_input($variables) { + $element = $variables['element']; + $attributes = $variables['attributes']; + return '' . drupal_render_children($element); +} + +/** + * Prepares an element to be rendered as a button. + * + * @param array $element + * An associative array containing the properties of the element. * Properties used: #attributes, #button_type, #name, #value. * * The #button_type property accepts any value, though core themes have css that * styles the following button_types appropriately: 'primary', 'danger'. * - * @ingroup themeable + * @return + * The modified element with button attributes. */ -function theme_button($variables) { - $element = $variables['element']; +function form_pre_render_button($element) { $element['#attributes']['type'] = 'submit'; element_set_attributes($element, array('id', 'name', 'value')); @@ -4129,24 +4141,23 @@ function theme_button($variables) { $element['#attributes']['class'][] = 'form-button-disabled'; } - return ''; + return $element; } /** - * Returns HTML for an image button form element. + * Prepares an element to be rendered as an image button. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #attributes, #button_type, #name, #value, #title, #src. * * The #button_type property accepts any value, though core themes have css that * styles the following button_types appropriately: 'primary', 'danger'. * - * @ingroup themeable + * @return + * The modified element with image button attributes. */ -function theme_image_button($variables) { - $element = $variables['element']; +function form_pre_render_image_button($element) { $element['#attributes']['type'] = 'image'; element_set_attributes($element, array('id', 'name', 'value')); @@ -4167,64 +4178,62 @@ function theme_image_button($variables) { $element['#attributes']['class'][] = 'image-button-disabled'; } - return ''; + return $element; } /** - * Returns HTML for a hidden form element. + * Prepares an element to be rendered as a hidden form element. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #name, #value, #attributes. * - * @ingroup themeable + * @return + * The modified element with hidden type attributes. */ -function theme_hidden($variables) { - $element = $variables['element']; +function form_pre_render_hidden($element) { $element['#attributes']['type'] = 'hidden'; element_set_attributes($element, array('name', 'value')); - return '\n"; + + return $element; } /** - * Returns HTML for a textfield form element. + * Prepares an element to be rendered as a textfield form element. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #title, #value, #description, #size, #maxlength, * #placeholder, #required, #attributes. * - * @ingroup themeable + * @return + * The modified element with textfield attributes. */ -function theme_textfield($variables) { - $element = $variables['element']; +function form_pre_render_textfield($element) { $element['#attributes']['type'] = 'text'; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder')); _form_set_attributes($element, array('form-text')); - return '' . drupal_render_children($element); + return $element; } /** - * Returns HTML for an email form element. + * Prepares an element to be rendered as an email form element. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #title, #value, #description, #size, #maxlength, * #placeholder, #required, #attributes. * - * @ingroup themeable + * @return + * The modified element with email attributes. */ -function theme_email($variables) { - $element = $variables['element']; +function form_pre_render_email($element) { $element['#attributes']['type'] = 'email'; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder')); _form_set_attributes($element, array('form-email')); - return '' . drupal_render_children($element); + return $element; } /** @@ -4242,69 +4251,60 @@ function form_validate_email(&$element, &$form_state) { } /** - * Returns HTML for a tel form element. + * Prepares an element to be rendered as a tel form element. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #title, #value, #description, #size, #maxlength, * #placeholder, #required, #attributes. * - * @ingroup themeable + * @return + * The modified element with tel attributes. */ -function theme_tel($variables) { - $element = $variables['element']; +function form_pre_render_tel($element) { $element['#attributes']['type'] = 'tel'; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder')); _form_set_attributes($element, array('form-tel')); - return '' . drupal_render_children($element); + return $element; } /** - * Returns HTML for a number form element. + * Prepares an element to be rendered as a number form element. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #title, #value, #description, #min, #max, #placeholder, * #required, #attributes, #step. * - * @ingroup themeable + * @return + * The modified element with number attributes. */ -function theme_number($variables) { - $element = $variables['element']; - +function form_pre_render_number($element) { $element['#attributes']['type'] = 'number'; element_set_attributes($element, array('id', 'name', 'value', 'step', 'min', 'max', 'placeholder')); _form_set_attributes($element, array('form-number')); - $output = ''; - - return $output; + return $element; } /** - * Returns HTML for a range form element. + * Prepares an element to be rendered as a range form element. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #title, #value, #description, #min, #max, #attributes, * #step. * - * @ingroup themeable + * @return + * The modified element with range attributes. */ -function theme_range($variables) { - $element = $variables['element']; - +function form_pre_render_range($element) { $element['#attributes']['type'] = 'range'; element_set_attributes($element, array('id', 'name', 'value', 'step', 'min', 'max')); _form_set_attributes($element, array('form-range')); - $output = ''; - - return $output; + return $element; } /** @@ -4378,43 +4378,41 @@ function form_type_range_value($element, $input = FALSE) { } /** - * Returns HTML for a URL form element. + * Prepares an element to be rendered as a URL form element. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #title, #value, #description, #size, #maxlength, * #placeholder, #required, #attributes. * - * @ingroup themeable + * @return + * The modified element with url attributes. */ -function theme_url($variables) { - $element = $variables['element']; +function form_pre_render_url($element) { $element['#attributes']['type'] = 'url'; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder')); _form_set_attributes($element, array('form-url')); - return '' . drupal_render_children($element); + return $element; } /** - * Returns HTML for a search form element. + * Prepares an element to be rendered as a search form element. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #title, #value, #description, #size, #maxlength, * #placeholder, #required, #attributes. * - * @ingroup themeable + * @return + * The modified element with search attributes. */ -function theme_search($variables) { - $element = $variables['element']; +function form_pre_render_search($element) { $element['#attributes']['type'] = 'search'; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder')); _form_set_attributes($element, array('form-search')); - return '' . drupal_render_children($element); + return $element; } /** @@ -4454,22 +4452,21 @@ function form_validate_color(&$element, &$form_state) { } /** - * Returns HTML for a color form element. + * Prepares an element to be rendered as a color form element. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #title, #value, #description, #attributes. * - * @ingroup themeable + * @return + * The modified element with color attributes. */ -function theme_color($variables) { - $element = $variables['element']; +function form_pre_render_color($element) { $element['#attributes']['type'] = 'color'; element_set_attributes($element, array('id', 'name', 'value')); _form_set_attributes($element, array('form-color')); - return '' . drupal_render_children($element); + return $element; } /** @@ -4527,23 +4524,22 @@ function theme_textarea($variables) { } /** - * Returns HTML for a password form element. + * Prepares an element to be rendered as a password form element. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #title, #value, #description, #size, #maxlength, * #placeholder, #required, #attributes. * - * @ingroup themeable + * @return + * The modified element with password attributes. */ -function theme_password($variables) { - $element = $variables['element']; +function form_pre_render_password($element) { $element['#attributes']['type'] = 'password'; element_set_attributes($element, array('id', 'name', 'size', 'maxlength', 'placeholder')); _form_set_attributes($element, array('form-text')); - return ''; + return $element; } /** @@ -4574,26 +4570,25 @@ function form_process_weight($element) { } /** - * Returns HTML for a file upload form element. + * Prepares an element to be rendered as a file upload form element. * * For assistance with handling the uploaded file correctly, see the API * provided by file.inc. * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. + * @param array $element + * An associative array containing the properties of the element. * Properties used: #title, #name, #size, #description, #required, * #attributes. * - * @ingroup themeable + * @return + * The modified element with file attributes. */ -function theme_file($variables) { - $element = $variables['element']; +function form_pre_render_file($element) { $element['#attributes']['type'] = 'file'; element_set_attributes($element, array('id', 'name', 'size')); _form_set_attributes($element, array('form-file')); - return ''; + return $element; } /** diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 35b9cd3..3c4a3d0 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -3244,6 +3244,9 @@ function drupal_common_theme() { 'variables' => array('primary' => array(), 'secondary' => array()), ), // From form.inc. + 'input' => array( + 'render element' => 'element', + ), 'select' => array( 'render element' => 'element', ), diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 6d16229..34279d3 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -296,8 +296,9 @@ function system_element_info() { '#is_button' => TRUE, '#executes_submit_callback' => TRUE, '#limit_validation_errors' => FALSE, + '#pre_render' => array('form_pre_render_button'), '#process' => array('form_process_button', 'ajax_process_form'), - '#theme_wrappers' => array('button'), + '#theme_wrappers' => array('input__button'), ); $types['button'] = array( '#input' => TRUE, @@ -305,27 +306,30 @@ function system_element_info() { '#is_button' => TRUE, '#executes_submit_callback' => FALSE, '#limit_validation_errors' => FALSE, + '#pre_render' => array('form_pre_render_button'), '#process' => array('form_process_button', 'ajax_process_form'), - '#theme_wrappers' => array('button'), + '#theme_wrappers' => array('input__button'), ); $types['image_button'] = array( '#input' => TRUE, '#is_button' => TRUE, '#executes_submit_callback' => TRUE, '#limit_validation_errors' => FALSE, + '#pre_render' => array('form_pre_render_image_button'), '#process' => array('form_process_button', 'ajax_process_form'), '#return_value' => TRUE, '#has_garbage_value' => TRUE, '#src' => NULL, - '#theme_wrappers' => array('image_button'), + '#theme_wrappers' => array('input__image_button'), ); $types['textfield'] = array( '#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE, + '#pre_render' => array('form_pre_render_textfield'), '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), - '#theme' => 'textfield', + '#theme' => 'input__textfield', '#theme_wrappers' => array('form_element'), ); $types['tel'] = array( @@ -333,8 +337,9 @@ function system_element_info() { '#size' => 30, '#maxlength' => 128, '#autocomplete_path' => FALSE, + '#pre_render' => array('form_pre_render_tel'), '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), - '#theme' => 'tel', + '#theme' => 'input__tel', '#theme_wrappers' => array('form_element'), ); $types['email'] = array( @@ -343,9 +348,10 @@ function system_element_info() { // user.module is not loaded in case of early bootstrap errors. '#maxlength' => defined('EMAIL_MAX_LENGTH') ? EMAIL_MAX_LENGTH : 255, '#autocomplete_path' => FALSE, + '#pre_render' => array('form_pre_render_email'), '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), '#element_validate' => array('form_validate_email'), - '#theme' => 'email', + '#theme' => 'input__email', '#theme_wrappers' => array('form_element'), ); $types['url'] = array( @@ -353,9 +359,10 @@ function system_element_info() { '#size' => 60, '#maxlength' => 255, '#autocomplete_path' => FALSE, + '#pre_render' => array('form_pre_render_url'), '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), '#element_validate' => array('form_validate_url'), - '#theme' => 'url', + '#theme' => 'input__url', '#theme_wrappers' => array('form_element'), ); $types['search'] = array( @@ -363,16 +370,18 @@ function system_element_info() { '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE, + '#pre_render' => array('form_pre_render_search'), '#process' => array('form_process_autocomplete', 'ajax_process_form'), - '#theme' => 'search', + '#theme' => 'input__search', '#theme_wrappers' => array('form_element'), ); $types['number'] = array( '#input' => TRUE, '#step' => 1, + '#pre_render' => array('form_pre_render_number'), '#process' => array('ajax_process_form'), '#element_validate' => array('form_validate_number'), - '#theme' => 'number', + '#theme' => 'input__number', '#theme_wrappers' => array('form_element'), ); $types['range'] = array( @@ -380,16 +389,18 @@ function system_element_info() { '#step' => 1, '#min' => 0, '#max' => 100, + '#pre_render' => array('form_pre_render_range'), '#process' => array('ajax_process_form'), '#element_validate' => array('form_validate_number'), - '#theme' => 'range', + '#theme' => 'input__range', '#theme_wrappers' => array('form_element'), ); $types['color'] = array( '#input' => TRUE, + '#pre_render' => array('form_pre_render_color'), '#process' => array('ajax_process_form'), '#element_validate' => array('form_validate_color'), - '#theme' => 'color', + '#theme' => 'input__color', '#theme_wrappers' => array('form_element'), ); $types['machine_name'] = array( @@ -408,8 +419,9 @@ function system_element_info() { '#input' => TRUE, '#size' => 60, '#maxlength' => 128, + '#pre_render' => array('form_pre_render_password'), '#process' => array('ajax_process_form', 'form_process_pattern'), - '#theme' => 'password', + '#theme' => 'input__password', '#theme_wrappers' => array('form_element'), ); $types['password_confirm'] = array( @@ -435,8 +447,9 @@ function system_element_info() { $types['radio'] = array( '#input' => TRUE, '#default_value' => NULL, + '#pre_render' => array('form_pre_render_radio'), '#process' => array('ajax_process_form'), - '#theme' => 'radio', + '#theme' => 'input__radio', '#theme_wrappers' => array('form_element'), '#title_display' => 'after', ); @@ -449,8 +462,9 @@ function system_element_info() { $types['checkbox'] = array( '#input' => TRUE, '#return_value' => 1, - '#theme' => 'checkbox', + '#pre_render' => array('form_pre_render_checkbox'), '#process' => array('form_process_checkbox', 'ajax_process_form'), + '#theme' => 'input__checkbox', '#theme_wrappers' => array('form_element'), '#title_display' => 'after', ); @@ -480,8 +494,9 @@ function system_element_info() { ); $types['file'] = array( '#input' => TRUE, + '#pre_render' => array('form_pre_render_file'), '#size' => 60, - '#theme' => 'file', + '#theme' => 'input__file', '#theme_wrappers' => array('form_element'), ); $types['tableselect'] = array( @@ -507,8 +522,9 @@ function system_element_info() { ); $types['hidden'] = array( '#input' => TRUE, + '#pre_render' => array('form_pre_render_hidden'), '#process' => array('ajax_process_form'), - '#theme' => 'hidden', + '#theme' => 'input__hidden', ); $types['value'] = array( '#input' => TRUE,