diff --git a/core/includes/form.inc b/core/includes/form.inc index 0ef70f8..a855434 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 a #type 'radio' render element for theme_input(). + * + * @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 array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'checkbox' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #title, #value, #return_value, #description, #required, - * #attributes, #checked. + * @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 array + * The $element with prepared variables ready for theme_input(). */ -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 theme_input(). * - * @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, #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'. + * Properties used: #attributes. * * @ingroup themeable */ -function theme_button($variables) { +function theme_input($variables) { $element = $variables['element']; + $attributes = $variables['attributes']; + return '' . drupal_render_children($element); +} + +/** + * Prepares a #type 'button' render element for theme_input(). + * + * @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'. + * + * @return array + * The $element with prepared variables ready for theme_input(). + */ +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 a #type 'image_button' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #attributes, #button_type, #name, #value, #title, #src. + * @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 array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'hidden' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #name, #value, #attributes. + * @param array $element + * An associative array containing the properties of the element. + * Properties used: #name, #value, #attributes. * - * @ingroup themeable + * @return array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'textfield' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #title, #value, #description, #size, #maxlength, - * #placeholder, #required, #attributes. + * @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 array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'email' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #title, #value, #description, #size, #maxlength, - * #placeholder, #required, #attributes. + * @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 array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'tel' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #title, #value, #description, #size, #maxlength, - * #placeholder, #required, #attributes. + * @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 array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'number' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #title, #value, #description, #min, #max, #placeholder, - * #required, #attributes, #step. + * @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 array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'range' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #title, #value, #description, #min, #max, #attributes, - * #step. + * @param array $element + * An associative array containing the properties of the element. + * Properties used: #title, #value, #description, #min, #max, #attributes, + * #step. * - * @ingroup themeable + * @return array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'url' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #title, #value, #description, #size, #maxlength, - * #placeholder, #required, #attributes. + * @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 array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'search' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #title, #value, #description, #size, #maxlength, - * #placeholder, #required, #attributes. + * @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 array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'color' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #title, #value, #description, #attributes. + * @param array $element + * An associative array containing the properties of the element. + * Properties used: #title, #value, #description, #attributes. * - * @ingroup themeable + * @return array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'password' render element for theme_input(). * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #title, #value, #description, #size, #maxlength, - * #placeholder, #required, #attributes. + * @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 array + * The $element with prepared variables ready for theme_input(). */ -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 a #type 'file' render element for theme_input(). * * 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. - * Properties used: #title, #name, #size, #description, #required, - * #attributes. + * @param array $element + * An associative array containing the properties of the element. + * Properties used: #title, #name, #size, #description, #required, + * #attributes. * - * @ingroup themeable + * @return array + * The $element with prepared variables ready for theme_input(). */ -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..9b50f90 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', ), @@ -3253,9 +3256,6 @@ function drupal_common_theme() { 'details' => array( 'render element' => 'element', ), - 'radio' => array( - 'render element' => 'element', - ), 'radios' => array( 'render element' => 'element', ), @@ -3265,57 +3265,15 @@ function drupal_common_theme() { 'exposed_filters' => array( 'render element' => 'form', ), - 'checkbox' => array( - 'render element' => 'element', - ), 'checkboxes' => array( 'render element' => 'element', ), - 'button' => array( - 'render element' => 'element', - ), - 'image_button' => array( - 'render element' => 'element', - ), - 'hidden' => array( - 'render element' => 'element', - ), - 'textfield' => array( - 'render element' => 'element', - ), - 'tel' => array( - 'render element' => 'element', - ), - 'email' => array( - 'render element' => 'element', - ), - 'url' => array( - 'render element' => 'element', - ), - 'number' => array( - 'render element' => 'element', - ), - 'range' => array( - 'render element' => 'element', - ), - 'color' => array( - 'render element' => 'element', - ), 'form' => array( 'render element' => 'element', ), 'textarea' => array( 'render element' => 'element', ), - 'search' => array( - 'render element' => 'element', - ), - 'password' => array( - 'render element' => 'element', - ), - 'file' => array( - 'render element' => 'element', - ), 'tableselect' => array( 'render element' => 'element', ), diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 60cd4e0..358d263 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -297,7 +297,8 @@ function system_element_info() { '#executes_submit_callback' => TRUE, '#limit_validation_errors' => FALSE, '#process' => array('form_process_button', 'ajax_process_form'), - '#theme_wrappers' => array('button'), + '#pre_render' => array('form_pre_render_button'), + '#theme_wrappers' => array('input__submit'), ); $types['button'] = array( '#input' => TRUE, @@ -306,7 +307,8 @@ function system_element_info() { '#executes_submit_callback' => FALSE, '#limit_validation_errors' => FALSE, '#process' => array('form_process_button', 'ajax_process_form'), - '#theme_wrappers' => array('button'), + '#pre_render' => array('form_pre_render_button'), + '#theme_wrappers' => array('input__button'), ); $types['image_button'] = array( '#input' => TRUE, @@ -317,7 +319,8 @@ function system_element_info() { '#return_value' => TRUE, '#has_garbage_value' => TRUE, '#src' => NULL, - '#theme_wrappers' => array('image_button'), + '#pre_render' => array('form_pre_render_image_button'), + '#theme_wrappers' => array('input__image_button'), ); $types['textfield'] = array( '#input' => TRUE, @@ -325,7 +328,8 @@ function system_element_info() { '#maxlength' => 128, '#autocomplete_path' => FALSE, '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), - '#theme' => 'textfield', + '#pre_render' => array('form_pre_render_textfield'), + '#theme' => 'input__textfield', '#theme_wrappers' => array('form_element'), ); $types['tel'] = array( @@ -334,7 +338,8 @@ function system_element_info() { '#maxlength' => 128, '#autocomplete_path' => FALSE, '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), - '#theme' => 'tel', + '#pre_render' => array('form_pre_render_tel'), + '#theme' => 'input__tel', '#theme_wrappers' => array('form_element'), ); $types['email'] = array( @@ -345,7 +350,8 @@ function system_element_info() { '#autocomplete_path' => FALSE, '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), '#element_validate' => array('form_validate_email'), - '#theme' => 'email', + '#pre_render' => array('form_pre_render_email'), + '#theme' => 'input__email', '#theme_wrappers' => array('form_element'), ); $types['url'] = array( @@ -355,7 +361,8 @@ function system_element_info() { '#autocomplete_path' => FALSE, '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), '#element_validate' => array('form_validate_url'), - '#theme' => 'url', + '#pre_render' => array('form_pre_render_url'), + '#theme' => 'input__url', '#theme_wrappers' => array('form_element'), ); $types['search'] = array( @@ -364,7 +371,8 @@ function system_element_info() { '#maxlength' => 128, '#autocomplete_path' => FALSE, '#process' => array('form_process_autocomplete', 'ajax_process_form'), - '#theme' => 'search', + '#pre_render' => array('form_pre_render_search'), + '#theme' => 'input__search', '#theme_wrappers' => array('form_element'), ); $types['number'] = array( @@ -372,7 +380,8 @@ function system_element_info() { '#step' => 1, '#process' => array('ajax_process_form'), '#element_validate' => array('form_validate_number'), - '#theme' => 'number', + '#pre_render' => array('form_pre_render_number'), + '#theme' => 'input__number', '#theme_wrappers' => array('form_element'), ); $types['range'] = array( @@ -382,14 +391,16 @@ function system_element_info() { '#max' => 100, '#process' => array('ajax_process_form'), '#element_validate' => array('form_validate_number'), - '#theme' => 'range', + '#pre_render' => array('form_pre_render_range'), + '#theme' => 'input__range', '#theme_wrappers' => array('form_element'), ); $types['color'] = array( '#input' => TRUE, '#process' => array('ajax_process_form'), '#element_validate' => array('form_validate_color'), - '#theme' => 'color', + '#pre_render' => array('form_pre_render_color'), + '#theme' => 'input__color', '#theme_wrappers' => array('form_element'), ); $types['machine_name'] = array( @@ -401,7 +412,8 @@ function system_element_info() { '#autocomplete_path' => FALSE, '#process' => array('form_process_machine_name', 'form_process_autocomplete', 'ajax_process_form'), '#element_validate' => array('form_validate_machine_name'), - '#theme' => 'textfield', + '#pre_render' => array('form_pre_render_textfield'), + '#theme' => 'input__textfield', '#theme_wrappers' => array('form_element'), ); $types['password'] = array( @@ -409,7 +421,8 @@ function system_element_info() { '#size' => 60, '#maxlength' => 128, '#process' => array('ajax_process_form', 'form_process_pattern'), - '#theme' => 'password', + '#pre_render' => array('form_pre_render_password'), + '#theme' => 'input__password', '#theme_wrappers' => array('form_element'), ); $types['password_confirm'] = array( @@ -436,21 +449,23 @@ function system_element_info() { '#input' => TRUE, '#default_value' => NULL, '#process' => array('ajax_process_form'), - '#theme' => 'radio', + '#pre_render' => array('form_pre_render_radio'), + '#theme' => 'input__radio', '#theme_wrappers' => array('form_element'), '#title_display' => 'after', ); $types['checkboxes'] = array( '#input' => TRUE, '#process' => array('form_process_checkboxes'), - '#theme_wrappers' => array('checkboxes'), '#pre_render' => array('form_pre_render_conditional_form_element'), + '#theme_wrappers' => array('checkboxes'), ); $types['checkbox'] = array( '#input' => TRUE, '#return_value' => 1, - '#theme' => 'checkbox', '#process' => array('form_process_checkbox', 'ajax_process_form'), + '#pre_render' => array('form_pre_render_checkbox'), + '#theme' => 'input__checkbox', '#theme_wrappers' => array('form_element'), '#title_display' => 'after', ); @@ -481,7 +496,8 @@ function system_element_info() { $types['file'] = array( '#input' => TRUE, '#size' => 60, - '#theme' => 'file', + '#pre_render' => array('form_pre_render_file'), + '#theme' => 'input__file', '#theme_wrappers' => array('form_element'), ); $types['tableselect'] = array( @@ -508,7 +524,13 @@ function system_element_info() { $types['hidden'] = array( '#input' => TRUE, '#process' => array('ajax_process_form'), - '#theme' => 'hidden', + '#pre_render' => array('form_pre_render_hidden'), + '#theme' => 'input__hidden', + ); + $types['token'] = array( + '#input' => TRUE, + '#pre_render' => array('form_pre_render_hidden'), + '#theme' => 'input__hidden', ); $types['value'] = array( '#input' => TRUE, @@ -533,32 +555,27 @@ function system_element_info() { '#theme_wrappers' => array('details'), ); $types['vertical_tabs'] = array( - '#theme_wrappers' => array('vertical_tabs'), '#default_tab' => '', '#process' => array('form_process_vertical_tabs'), + '#theme_wrappers' => array('vertical_tabs'), ); $types['dropbutton'] = array( - '#theme' => 'links__dropbutton', '#pre_render' => array('drupal_pre_render_dropbutton'), + '#theme' => 'links__dropbutton', ); $types['operations'] = array( - '#theme' => 'links__dropbutton__operations', '#pre_render' => array('drupal_pre_render_dropbutton'), + '#theme' => 'links__dropbutton__operations', ); $types['container'] = array( - '#theme_wrappers' => array('container'), '#process' => array('form_process_container'), + '#theme_wrappers' => array('container'), ); $types['actions'] = array( - '#theme_wrappers' => array('container'), '#process' => array('form_process_actions', 'form_process_container'), '#weight' => 100, - ); - - $types['token'] = array( - '#input' => TRUE, - '#theme' => 'hidden', + '#theme_wrappers' => array('container'), ); $types['table'] = array(