From 29c8e40e912f8975011224f824977b2353fe07b5 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Tue, 3 Feb 2009 18:55:32 +0000 Subject: [PATCH] - Patch #355236 by Frando: refactor drupal_render() theming. --- includes/common.inc | 211 +++++++++++++++--------- includes/form.inc | 132 ++++----------- includes/locale.inc | 2 +- includes/theme.inc | 2 +- modules/aggregator/aggregator.pages.inc | 2 +- modules/block/block.admin.inc | 2 +- modules/color/color.module | 2 +- modules/filter/filter.admin.inc | 4 +- modules/menu/menu.admin.inc | 2 +- modules/node/node.admin.inc | 4 +- modules/node/node.module | 4 +- modules/node/node.pages.inc | 2 +- modules/poll/poll.module | 4 +- modules/profile/profile.admin.inc | 2 +- modules/system/system.admin.inc | 4 +- modules/system/system.module | 37 ++++- modules/taxonomy/taxonomy.admin.inc | 4 +- modules/trigger/trigger.admin.inc | 4 +- modules/upload/upload.module | 4 +- modules/user/user.admin.inc | 8 +- modules/user/user.module | 8 +- 21 files changed, 237 insertions(+), 207 deletions(-) diff --git a/includes/common.inc b/includes/common.inc index 09bd204e468..5dfc001caab 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -3217,7 +3217,7 @@ function drupal_alter($type, &$data) { */ function drupal_get_page($content = NULL) { // Initialize page array with defaults. @see hook_elements() - 'page' element. - $page = _element_info('page'); + $page = element_info('page'); $page['content'] = is_array($content) ? $content : array('main' => array('#markup' => $content)); return $page; @@ -3253,6 +3253,28 @@ function drupal_render_page($page) { * Renders HTML given a structured array tree. * * Recursively iterates over each of the array elements, generating HTML code. + * + * HTML generation is controlled by two properties containing theme functions, + * #theme and #theme_wrapper. + * + * #theme is the theme function called first. If it is set and the element has any + * children, they have to be rendered there. For elements that are not allowed + * to have any children, e.g. buttons or textfields, it can be used to render + * the element itself. If #theme is not present and the element has children, + * they are rendered and concatenated into a string by drupal_render_children(). + * + * The theme function in #theme_wrapper will be called after #theme has run. It + * can be used to add further markup around the rendered children, e.g. fieldsets + * add the required markup for a fieldset around their rendered child elements. + * A wrapper theme function always has to include the element's #children property + * in its output, as this contains the rendered children. + * + * For example, for the form element type, by default only the #theme_wrapper + * property is set, which adds the form markup around the rendered child elements + * of the form. This allows you to set the #theme property on a specific form to + * a custom theme function, giving you complete control over the placement of the + * form's children while not at all having to deal with the form markup itself. + * * This function is usually called from within a another function, like * drupal_get_form() or node_view(). Elements are sorted internally using * uasort(). Since this is expensive, when passing already sorted elements to @@ -3267,15 +3289,27 @@ function drupal_render_page($page) { function drupal_render(&$elements) { // Early-return nothing if user does not have access. if (!isset($elements) || (isset($elements['#access']) && !$elements['#access'])) { - return NULL; + return; } - // If the default values for this element haven't been loaded yet, populate + // Do not print elements twice. + if (isset($elements['#printed']) && $elements['#printed']) { + return; + } + + // If the default values for this element have not been loaded yet, populate // them. - if (!isset($elements['#defaults_loaded']) || !$elements['#defaults_loaded']) { - if ((!empty($elements['#type'])) && ($info = _element_info($elements['#type']))) { - $elements += $info; - } + if (isset($elements['#type']) && empty($elements['#defaults_loaded'])) { + $elements += element_info($elements['#type']); + } + else { + $elements += element_basic_defaults(); + } + + // If #markup is not empty and no theme function is set, use theme_markup. + // This allows to specify just #markup on an element without setting the #type. + if (!empty($elements['#markup']) && empty($elements['#theme'])) { + $elements['#theme'] = 'markup'; } // Make any final changes to the element before it is rendered. This means @@ -3297,68 +3331,63 @@ function drupal_render(&$elements) { $elements['#sorted'] = TRUE; } - $content = ''; - $elements += array('#title' => NULL, '#description' => NULL); - if (!isset($elements['#children'])) { - $children = element_children($elements); - // Render all the children that use a theme function. - if (isset($elements['#theme']) && empty($elements['#theme_used'])) { - $elements['#theme_used'] = TRUE; + $elements['#children'] = ''; + // Call the element's #theme function if it is set. Then any children of the + // element have to be rendered there. + if (isset($elements['#theme'])) { + $elements['#children'] = theme($elements['#theme'], $elements); + } + // If #theme was not set and the element has children, render them now + // using drupal_render_children(). + if ($elements['#children'] == '') { + $elements['#children'] = drupal_render_children($elements); + } - $previous = array(); - foreach (array('#type', '#prefix', '#suffix') as $key) { - $previous[$key] = isset($elements[$key]) ? $elements[$key] : NULL; - } - // If we rendered a single element, then we will skip the renderer. - if (empty($children)) { - $elements['#printed'] = TRUE; - } - else { - $elements['#markup'] = ''; - } + // Let the theme function in #theme_wrapper add markup around the rendered + // children. + if (!empty($elements['#theme_wrapper'])) { + $elements['#children'] = theme($elements['#theme_wrapper'], $elements); + } - unset($elements['#type'], $elements['#prefix'], $elements['#suffix']); - $content = theme($elements['#theme'], $elements); - - foreach (array('#type', '#prefix', '#suffix') as $key) { - $elements[$key] = isset($previous[$key]) ? $previous[$key] : NULL; - } - } - // Render each of the children using drupal_render and concatenate them. - if (!isset($content) || $content === '') { - foreach ($children as $key) { - $content .= drupal_render($elements[$key]); + // Filter the outputted content and make any last changes before the + // content is sent to the browser. The changes are made on $content + // which allows the output'ed text to be filtered. + if (isset($elements['#post_render'])) { + foreach ($elements['#post_render'] as $function) { + if (drupal_function_exists($function)) { + $elements['#children'] = $function($elements['#children'], $elements); } } } - if (isset($content) && $content !== '') { - $elements['#children'] = $content; - } - // Until now, we rendered the children, here we render the element itself - if (!isset($elements['#printed'])) { - $content = theme(!empty($elements['#type']) ? $elements['#type'] : 'markup', $elements); - $elements['#printed'] = TRUE; - } + $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : ''; + $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : ''; - if (isset($content) && $content !== '') { - // Filter the outputted content and make any last changes before the - // content is sent to the browser. The changes are made on $content - // which allows the output'ed text to be filtered. - if (isset($elements['#post_render'])) { - foreach ($elements['#post_render'] as $function) { - if (drupal_function_exists($function)) { - $content = $function($content, $elements); - } - } - } - $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : ''; - $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : ''; - $content = $prefix . $content . $suffix; - // Store the rendered content, so higher level elements can reuse it. - $elements['#content'] = $content; - return $content; + $elements['#printed'] = TRUE; + return $prefix . $elements['#children'] . $suffix; +} + +/** + * Render children of an element and concatenate them. + * + * This renders all children of an element using drupal_render() and then + * joins them together into a single string. + * + * @param $element + * The structured array whose children shall be rendered. + * @param $children_keys + * If the keys of the element's children are already known, they can be passed + * in to save another run of element_children(). + */ +function drupal_render_children($element, $children_keys = NULL) { + if ($children_keys === NULL) { + $children_keys = element_children($element); } + $output = ''; + foreach ($children_keys as $key) { + $output .= drupal_render($element[$key]); + } + return $output; } /** @@ -3373,6 +3402,44 @@ function element_sort($a, $b) { return ($a_weight < $b_weight) ? -1 : 1; } +/** + * Retrieve the default properties for the defined element type. + */ +function element_info($type, $refresh = NULL) { + static $cache; + + if (!isset($cache) || $refresh) { + $basic_defaults = element_basic_defaults(); + $cache = array(); + foreach (module_implements('elements') as $module) { + $elements = module_invoke($module, 'elements'); + if (isset($elements) && is_array($elements)) { + $cache = array_merge_recursive($cache, $elements); + } + } + if (!empty($cache)) { + foreach ($cache as $element_type => $info) { + $cache[$element_type] = array_merge_recursive($basic_defaults, $info); + $cache[$element_type]['#type'] = $element_type; + } + } + } + + return $cache[$type]; +} + +/** + * Retrieve the basic default properties that are common to all elements. + */ +function element_basic_defaults() { + return array( + '#description' => '', + '#title' => '', + '#attributes' => array(), + '#required' => FALSE, + ); +} + /** * Function used by uasort to sort structured arrays by weight, without the property weight prefix. */ @@ -3410,7 +3477,13 @@ function element_child($key) { * Get keys of a structured array tree element that are not properties (i.e., do not begin with '#'). */ function element_children($element) { - return array_filter(array_keys((array) $element), 'element_child'); + $keys = array(); + foreach(array_keys($element) as $key) { + if ($key[0] !== '#') { + $keys[] = $key; + } + } + return $keys; } /** @@ -3564,24 +3637,15 @@ function drupal_common_theme() { 'radios' => array( 'arguments' => array('element' => NULL), ), - 'password_confirm' => array( - 'arguments' => array('element' => NULL), - ), 'date' => array( 'arguments' => array('element' => NULL), ), - 'item' => array( - 'arguments' => array('element' => NULL), - ), 'checkbox' => array( 'arguments' => array('element' => NULL), ), 'checkboxes' => array( 'arguments' => array('element' => NULL), ), - 'submit' => array( - 'arguments' => array('element' => NULL), - ), 'button' => array( 'arguments' => array('element' => NULL), ), @@ -3591,9 +3655,6 @@ function drupal_common_theme() { 'hidden' => array( 'arguments' => array('element' => NULL), ), - 'token' => array( - 'arguments' => array('element' => NULL), - ), 'textfield' => array( 'arguments' => array('element' => NULL), ), @@ -3616,7 +3677,7 @@ function drupal_common_theme() { 'arguments' => array('element' => NULL), ), 'form_element' => array( - 'arguments' => array('element' => NULL, 'value' => NULL), + 'arguments' => array('element' => NULL), ), ); } diff --git a/includes/form.inc b/includes/form.inc index 23973c8a0d1..5e911ed63d5 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -512,7 +512,7 @@ function drupal_prepare_form($form_id, &$form, &$form_state) { $form['#id'] = form_clean_id($form_id); } - $form += _element_info('form'); + $form += element_info('form'); $form += array('#tree' => FALSE, '#parents' => array()); if (!isset($form['#validate'])) { @@ -861,7 +861,7 @@ function form_builder($form_id, $form, &$form_state) { $form['#processed'] = FALSE; // Use element defaults. - if ((!empty($form['#type'])) && ($info = _element_info($form['#type']))) { + if ((!empty($form['#type'])) && ($info = element_info($form['#type']))) { // Overlay $info onto $form, retaining preexisting keys in $form. $form += $info; } @@ -1348,35 +1348,6 @@ function _form_set_value(&$form_values, $form_item, $parents, $value) { } } -/** - * Retrieve the default properties for the defined element type. - */ -function _element_info($type, $refresh = NULL) { - static $cache; - - $basic_defaults = array( - '#description' => NULL, - '#attributes' => array(), - '#required' => FALSE, - ); - if (!isset($cache) || $refresh) { - $cache = array(); - foreach (module_implements('elements') as $module) { - $elements = module_invoke($module, 'elements'); - if (isset($elements) && is_array($elements)) { - $cache = array_merge_recursive($cache, $elements); - } - } - if (sizeof($cache)) { - foreach ($cache as $element_type => $info) { - $cache[$element_type] = array_merge_recursive($basic_defaults, $info); - } - } - } - - return $cache[$type]; -} - function form_options_flatten($array, $reset = TRUE) { static $return; @@ -1419,7 +1390,7 @@ function theme_select($element) { $size = $element['#size'] ? ' size="' . $element['#size'] . '"' : ''; _form_set_class($element, array('form-select')); $multiple = $element['#multiple']; - return theme('form_element', $element, ''); + return ''; } function form_select_options($element, $choices = NULL) { @@ -1555,8 +1526,7 @@ function theme_radio($element) { $output = ''; } - unset($element['#title']); - return theme('form_element', $element, $output); + return $output; } /** @@ -1576,28 +1546,8 @@ function theme_radios($element) { $class .= ' ' . $element['#attributes']['class']; } $element['#children'] = '
' . (!empty($element['#children']) ? $element['#children'] : '') . '
'; - if ($element['#title'] || $element['#description']) { - unset($element['#id']); - return theme('form_element', $element, $element['#children']); - } - else { - return $element['#children']; - } -} -/** - * Format a password_confirm item. - * - * @param $element - * An associative array containing the properties of the element. - * Properties used: title, value, id, required, error. - * @return - * A themed HTML string representing the form item. - * - * @ingroup themeable - */ -function theme_password_confirm($element) { - return theme('form_element', $element, $element['#children']); + return $element['#children']; } /** @@ -1665,7 +1615,7 @@ function password_confirm_validate($form, &$form_state) { * @ingroup themeable */ function theme_date($element) { - return theme('form_element', $element, '
' . $element['#children'] . '
'); + return '
' . drupal_render_children($element) . '
'; } /** @@ -1881,6 +1831,8 @@ function form_process_input_format($element) { // We need to break references, otherwise form_builder recurses infinitely. $element['value'] = (array)$element; $element['#type'] = 'markup'; + $element['#theme'] = NULL; + $element['#theme_wrapper'] = NULL; $element['format'] = filter_form($element['#text_format'], 1, $element_parents); // We need to clear the #text_format from the new child otherwise we @@ -1976,21 +1928,6 @@ function form_process_ahah($element) { return $element; } -/** - * Format a form item. - * - * @param $element - * An associative array containing the properties of the element. - * Properties used: title, value, description, required, error - * @return - * A themed HTML string representing the form item. - * - * @ingroup themeable - */ -function theme_item($element) { - return theme('form_element', $element, $element['#markup'] . (!empty($element['#children']) ? $element['#children'] : '')); -} - /** * Format a checkbox. * @@ -2016,8 +1953,7 @@ function theme_checkbox($element) { $checkbox = ''; } - unset($element['#title']); - return theme('form_element', $element, $checkbox); + return $checkbox; } /** @@ -2036,13 +1972,21 @@ function theme_checkboxes($element) { $class .= ' ' . $element['#attributes']['class']; } $element['#children'] = '
' . (!empty($element['#children']) ? $element['#children'] : '') . '
'; + + return $element['#children']; +} + +/** + * Add form_element theming to an element if title or desription is set. + * + * This is used as a pre render function for checkboxes and radios. + */ +function form_pre_render_conditional_form_element($element) { if ($element['#title'] || $element['#description']) { unset($element['#id']); - return theme('form_element', $element, $element['#children']); - } - else { - return $element['#children']; + $element['#theme_wrapper'] = 'form_element'; } + return $element; } function form_process_checkboxes($element) { @@ -2090,7 +2034,7 @@ function theme_tableselect($element) { $row = array(); // Render the checkbox / radio element. - $row[] = $element[$key]['#content']; + $row[] = drupal_render($element[$key]); // As theme_table only maps header and row columns by order, create the // correct order by iterating over the header fields. @@ -2243,15 +2187,6 @@ function theme_hidden($element) { return '\n"; } -/** - * Format a form token. - * - * @ingroup themeable - */ -function theme_token($element) { - return theme('hidden', $element); -} - /** * Format a textfield. * @@ -2286,8 +2221,7 @@ function theme_textfield($element) { if (isset($element['#field_suffix'])) { $output .= ' ' . $element['#field_suffix'] . ''; } - - return theme('form_element', $element, $output) . $extra; + return $output . $extra; } /** @@ -2337,7 +2271,7 @@ function theme_textarea($element) { } _form_set_class($element, $class); - return theme('form_element', $element, ''); + return ''; } /** @@ -2355,7 +2289,7 @@ function theme_textarea($element) { */ function theme_markup($element) { - return (isset($element['#markup']) ? $element['#markup'] : '') . (isset($element['#children']) ? $element['#children'] : ''); + return (!empty($element['#markup']) ? $element['#markup'] : '') . drupal_render_children($element); } /** @@ -2375,7 +2309,7 @@ function theme_password($element) { _form_set_class($element, array('form-text')); $output = ''; - return theme('form_element', $element, $output); + return $output; } /** @@ -2388,7 +2322,7 @@ function form_process_weight($element) { $element['#options'] = $weights; $element['#type'] = 'select'; $element['#is_weight'] = TRUE; - $element += _element_info('select'); + $element += element_info('select'); return $element; } @@ -2415,7 +2349,7 @@ function form_process_weight($element) { */ function theme_file($element) { _form_set_class($element, array('form-file')); - return theme('form_element', $element, '\n"); + return '\n"; } /** @@ -2423,15 +2357,13 @@ function theme_file($element) { * * @param element * An associative array containing the properties of the element. - * Properties used: title, description, id, required - * @param $value - * The form element's data. + * Properties used: title, description, id, required, children * @return * A string representing the form element. * * @ingroup themeable */ -function theme_form_element($element, $value) { +function theme_form_element($element) { // This is also used in the installer, pre-database setup. $t = get_t(); @@ -2442,7 +2374,7 @@ function theme_form_element($element, $value) { $output .= ">\n"; $required = !empty($element['#required']) ? '*' : ''; - if (!empty($element['#title'])) { + if (!empty($element['#title']) && empty($element['#form_element_skip_title'])) { $title = $element['#title']; if (!empty($element['#id'])) { $output .= ' \n"; @@ -2452,7 +2384,7 @@ function theme_form_element($element, $value) { } } - $output .= " $value\n"; + $output .= " " . $element['#children'] . "\n"; if (!empty($element['#description'])) { $output .= '
' . $element['#description'] . "
\n"; diff --git a/includes/locale.inc b/includes/locale.inc index 74b6efc7d9f..c5fcb592bc9 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -96,7 +96,7 @@ function theme_locale_languages_overview_form($form) { } $header = array(array('data' => t('English name')), array('data' => t('Native name')), array('data' => t('Code')), array('data' => t('Direction')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Weight')), array('data' => t('Operations'))); $output = theme('table', $header, $rows, array('id' => 'language-order')); - $output .= drupal_render($form); + $output .= drupal_render_children($form); drupal_add_tabledrag('language-order', 'order', 'sibling', 'language-order-weight'); diff --git a/includes/theme.inc b/includes/theme.inc index 57989cc5b4c..606beebf19d 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -1584,7 +1584,7 @@ function theme_item_list($items = array(), $title = NULL, $type = 'ul', $attribu */ function theme_list($elements) { // Populate any missing array elements with their defaults. - $elements += _element_info('list'); + $elements += element_info('list'); return theme('item_list', $elements['#items'], $elements['#title'], $elements['#list_type'], $elements['#attributes']); } diff --git a/modules/aggregator/aggregator.pages.inc b/modules/aggregator/aggregator.pages.inc index 99dec6037c6..c311dab147a 100644 --- a/modules/aggregator/aggregator.pages.inc +++ b/modules/aggregator/aggregator.pages.inc @@ -250,7 +250,7 @@ function theme_aggregator_categorize_items($form) { } $output .= theme('table', array('', t('Categorize')), $rows); $output .= drupal_render($form['submit']); - $output .= drupal_render($form); + $output .= drupal_render_children($form); return theme('aggregator_wrapper', $output); } diff --git a/modules/block/block.admin.inc b/modules/block/block.admin.inc index 00afc9bd82a..6dd17f30883 100644 --- a/modules/block/block.admin.inc +++ b/modules/block/block.admin.inc @@ -403,5 +403,5 @@ function template_preprocess_block_admin_display_form(&$variables) { } } - $variables['form_submit'] = drupal_render($variables['form']); + $variables['form_submit'] = drupal_render_children($variables['form']); } diff --git a/modules/color/color.module b/modules/color/color.module index d64a64b64cc..b9e30f67b7e 100644 --- a/modules/color/color.module +++ b/modules/color/color.module @@ -239,7 +239,7 @@ function theme_color_scheme_form($form) { } $output .= ''; // Preview - $output .= drupal_render($form); + $output .= drupal_render_children($form); $output .= '

' . t('Preview') . '

'; $output .= '

Lorem ipsum dolor

Sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

'; // Close the wrapper div. diff --git a/modules/filter/filter.admin.inc b/modules/filter/filter.admin.inc index 24879538d51..89453313248 100644 --- a/modules/filter/filter.admin.inc +++ b/modules/filter/filter.admin.inc @@ -82,7 +82,7 @@ function theme_filter_admin_overview($form) { } $header = array(t('Name'), t('Roles'), t('Default'), t('Weight'), array('data' => t('Operations'), 'colspan' => 2)); $output = theme('table', $header, $rows, array('id' => 'input-format-order')); - $output .= drupal_render($form); + $output .= drupal_render_children($form); drupal_add_tabledrag('input-format-order', 'order', 'sibling', 'input-format-order-weight'); @@ -391,7 +391,7 @@ function theme_filter_admin_order($form) { } $output = theme('table', $header, $rows, array('id' => 'filter-order')); - $output .= drupal_render($form); + $output .= drupal_render_children($form); drupal_add_tabledrag('filter-order', 'order', 'sibling', 'filter-order-weight', NULL, NULL, FALSE); diff --git a/modules/menu/menu.admin.inc b/modules/menu/menu.admin.inc index 8d6db3c44ff..d793c88f727 100644 --- a/modules/menu/menu.admin.inc +++ b/modules/menu/menu.admin.inc @@ -216,7 +216,7 @@ function theme_menu_overview_form($form) { if ($rows) { $output .= theme('table', $header, $rows, array('id' => 'menu-overview')); } - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } diff --git a/modules/node/node.admin.inc b/modules/node/node.admin.inc index 4ae27118bf6..9fabbf689dc 100644 --- a/modules/node/node.admin.inc +++ b/modules/node/node.admin.inc @@ -269,7 +269,7 @@ function theme_node_filter_form($form) { $output .= '
'; $output .= drupal_render($form['filters']); $output .= '
'; - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } @@ -616,7 +616,7 @@ function theme_node_admin_nodes($form) { $output .= drupal_render($form['pager']); } - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } diff --git a/modules/node/node.module b/modules/node/node.module index e25e86bc973..1e73c195871 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1612,7 +1612,7 @@ function theme_node_search_admin($form) { } $output .= theme('table', $header, $rows); - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } @@ -3138,7 +3138,7 @@ function node_list_permissions($type) { * Implementation of hook_elements(). */ function node_elements() { - $type['node_links'] = array(); + $type['node_links'] = array('#theme' => 'node_links'); return $type; } diff --git a/modules/node/node.pages.inc b/modules/node/node.pages.inc index 87106deed46..03866ec8b93 100644 --- a/modules/node/node.pages.inc +++ b/modules/node/node.pages.inc @@ -335,7 +335,7 @@ function theme_node_form($form) { $output = "\n
\n"; $output .= "
\n"; - $output .= drupal_render($form); + $output .= drupal_render_children($form); $output .= "
\n"; $output .= "
\n"; diff --git a/modules/poll/poll.module b/modules/poll/poll.module index 45de98605d1..fe82f98b411 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -624,7 +624,7 @@ function template_preprocess_poll_vote(&$variables) { $variables['choice'] = drupal_render($form['choice']); $variables['title'] = check_plain($form['#node']->title); $variables['vote'] = drupal_render($form['vote']); - $variables['rest'] = drupal_render($form); + $variables['rest'] = drupal_render_children($form); $variables['block'] = $form['#block']; // If this is a block, allow a different tpl.php to be used. if ($variables['block']) { @@ -698,7 +698,7 @@ function theme_poll_choices($form) { } $output = theme('table', $headers, $rows, array('id' => 'poll-choice-table')); - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } diff --git a/modules/profile/profile.admin.inc b/modules/profile/profile.admin.inc index 67e1d0b8ee1..e0252ce104d 100644 --- a/modules/profile/profile.admin.inc +++ b/modules/profile/profile.admin.inc @@ -152,7 +152,7 @@ function theme_profile_admin_overview($form) { $header[] = array('data' => t('Operations'), 'colspan' => 2); $output = theme('table', $header, $rows, array('id' => 'profile-fields')); - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index be461d72774..74021478364 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -2174,7 +2174,7 @@ function theme_system_modules_uninstall($form) { } $output = theme('table', $header, $rows); - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } @@ -2256,6 +2256,6 @@ function theme_system_themes_form($form) { $header = array(t('Screenshot'), t('Name'), t('Version'), t('Enabled'), t('Default'), t('Operations')); $output = theme('table', $header, $rows); - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } diff --git a/modules/system/system.module b/modules/system/system.module index 0db103ae3b0..33386da6d57 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -235,6 +235,7 @@ function system_elements() { $type['form'] = array( '#method' => 'post', '#action' => request_uri(), + '#theme_wrapper' => 'form', ); $type['page'] = array( @@ -259,6 +260,7 @@ function system_elements() { '#button_type' => 'submit', '#executes_submit_callback' => TRUE, '#process' => array('form_process_ahah'), + '#theme_wrapper' => 'button', ); $type['button'] = array( @@ -267,6 +269,7 @@ function system_elements() { '#button_type' => 'submit', '#executes_submit_callback' => FALSE, '#process' => array('form_process_ahah'), + '#theme_wrapper' => 'button', ); $type['image_button'] = array( @@ -277,6 +280,7 @@ function system_elements() { '#return_value' => TRUE, '#has_garbage_value' => TRUE, '#src' => NULL, + '#theme_wrapper' => 'image_button', ); $type['textfield'] = array( @@ -285,6 +289,8 @@ function system_elements() { '#maxlength' => 128, '#autocomplete_path' => FALSE, '#process' => array('form_process_input_format', 'form_process_ahah'), + '#theme' => 'textfield', + '#theme_wrapper' => 'form_element', ); $type['password'] = array( @@ -292,11 +298,14 @@ function system_elements() { '#size' => 60, '#maxlength' => 128, '#process' => array('form_process_ahah'), + '#theme' => 'password', + '#theme_wrapper' => 'form_element', ); $type['password_confirm'] = array( '#input' => TRUE, '#process' => array('form_process_password_confirm'), + '#theme_wrapper' => 'form_element', ); $type['textarea'] = array( @@ -305,29 +314,41 @@ function system_elements() { '#rows' => 5, '#resizable' => TRUE, '#process' => array('form_process_input_format', 'form_process_ahah'), + '#theme' => 'textarea', + '#theme_wrapper' => 'form_element', ); $type['radios'] = array( '#input' => TRUE, '#process' => array('form_process_radios'), + '#theme_wrapper' => 'radios', + '#pre_render' => array('form_pre_render_conditional_form_element'), ); $type['radio'] = array( '#input' => TRUE, '#default_value' => NULL, '#process' => array('form_process_ahah'), + '#theme' => 'radio', + '#theme_wrapper' => 'form_element', + '#form_element_skip_title' => TRUE, ); $type['checkboxes'] = array( '#input' => TRUE, '#tree' => TRUE, '#process' => array('form_process_checkboxes'), + '#theme_wrapper' => 'checkboxes', + '#pre_render' => array('form_pre_render_conditional_form_element'), ); $type['checkbox'] = array( '#input' => TRUE, '#return_value' => 1, '#process' => array('form_process_ahah'), + '#theme' => 'checkbox', + '#theme_wrapper' => 'form_element', + '#form_element_skip_title' => TRUE, ); $type['select'] = array( @@ -335,6 +356,8 @@ function system_elements() { '#size' => 0, '#multiple' => FALSE, '#process' => array('form_process_ahah'), + '#theme' => 'select', + '#theme_wrapper' => 'form_element', ); $type['weight'] = array( @@ -348,11 +371,15 @@ function system_elements() { '#input' => TRUE, '#element_validate' => array('date_validate'), '#process' => array('form_process_date'), + '#theme' => 'date', + '#theme_wrapper' => 'form_element', ); $type['file'] = array( '#input' => TRUE, '#size' => 60, + '#theme' => 'file', + '#theme_wrapper' => 'form_element', ); $type['tableselect'] = array( '#input' => TRUE, @@ -361,6 +388,7 @@ function system_elements() { '#process' => array('form_process_tableselect'), '#options' => array(), '#empty' => '', + '#theme' => 'tableselect' ); /** @@ -368,11 +396,14 @@ function system_elements() { */ $type['item'] = array( '#markup' => '', + '#theme' => 'markup', + '#theme_wrapper' => 'form_element', ); $type['hidden'] = array( '#input' => TRUE, '#process' => array('form_process_ahah'), + '#theme' => 'hidden', ); $type['value'] = array( @@ -380,8 +411,8 @@ function system_elements() { ); $type['markup'] = array( - '#prefix' => '', - '#suffix' => '', + '#markup' => '', + '#theme' => 'markup', ); $type['fieldset'] = array( @@ -389,10 +420,12 @@ function system_elements() { '#collapsed' => FALSE, '#value' => NULL, '#process' => array('form_process_ahah'), + '#theme_wrapper' => 'fieldset', ); $type['token'] = array( '#input' => TRUE, + '#theme' => array('hidden'), ); return $type; diff --git a/modules/taxonomy/taxonomy.admin.inc b/modules/taxonomy/taxonomy.admin.inc index 3d9bd50929c..1129e33c9e5 100644 --- a/modules/taxonomy/taxonomy.admin.inc +++ b/modules/taxonomy/taxonomy.admin.inc @@ -91,7 +91,7 @@ function theme_taxonomy_overview_vocabularies($form) { drupal_add_tabledrag('taxonomy', 'order', 'sibling', 'vocabulary-weight'); } $header[] = array('data' => t('Operations'), 'colspan' => '3'); - return theme('table', $header, $rows, array('id' => 'taxonomy')) . drupal_render($form); + return theme('table', $header, $rows, array('id' => 'taxonomy')) . drupal_render_children($form); } /** @@ -605,7 +605,7 @@ function theme_taxonomy_overview_terms($form) { $header = array(t('Name'), t('Operations')); $output = theme('table', $header, $rows, array('id' => 'taxonomy')); - $output .= drupal_render($form); + $output .= drupal_render_children($form); $output .= theme('pager', NULL, $page_increment); return $output; diff --git a/modules/trigger/trigger.admin.inc b/modules/trigger/trigger.admin.inc index 9d647db7c34..5a33b6249df 100644 --- a/modules/trigger/trigger.admin.inc +++ b/modules/trigger/trigger.admin.inc @@ -246,10 +246,10 @@ function theme_trigger_display($element) { } if (count($rows)) { - $output = theme('table', $header, $rows) . drupal_render($element); + $output = theme('table', $header, $rows) . drupal_render_children($element); } else { - $output = drupal_render($element); + $output = drupal_render_children($element); } return $output; } diff --git a/modules/upload/upload.module b/modules/upload/upload.module index 0971c978bb8..d61433aac04 100644 --- a/modules/upload/upload.module +++ b/modules/upload/upload.module @@ -621,7 +621,7 @@ function theme_upload_form_current($form) { $rows[] = array('data' => $row, 'class' => 'draggable'); } $output = theme('table', $header, $rows, array('id' => 'upload-attachments')); - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } @@ -633,7 +633,7 @@ function theme_upload_form_current($form) { */ function theme_upload_form_new($form) { drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight'); - $output = drupal_render($form); + $output = drupal_render_children($form); return $output; } diff --git a/modules/user/user.admin.inc b/modules/user/user.admin.inc index 6a2b05136b5..b0e8d50a5f7 100644 --- a/modules/user/user.admin.inc +++ b/modules/user/user.admin.inc @@ -651,7 +651,7 @@ function theme_user_admin_perm($form) { } $output = theme('system_compact_link'); $output .= theme('table', $header, $rows, array('id' => 'permissions')); - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } @@ -788,7 +788,7 @@ function theme_user_admin_account($form) { $output .= drupal_render($form['pager']); } - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } @@ -811,7 +811,7 @@ function theme_user_admin_new_role($form) { } $rows[] = array(drupal_render($form['name']), array('data' => drupal_render($form['submit']), 'colspan' => 2)); - $output = drupal_render($form); + $output = drupal_render_children($form); $output .= theme('table', $header, $rows); return $output; @@ -826,7 +826,7 @@ function theme_user_filter_form($form) { $output = '
'; $output .= drupal_render($form['filters']); $output .= '
'; - $output .= drupal_render($form); + $output .= drupal_render_children($form); return $output; } diff --git a/modules/user/user.module b/modules/user/user.module index 39e98e8e8bc..b430121d41d 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -753,8 +753,12 @@ function user_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) { */ function user_elements() { return array( - 'user_profile_category' => array(), - 'user_profile_item' => array(), + 'user_profile_category' => array( + '#theme_wrapper' => 'user_profile_category' + ), + 'user_profile_item' => array( + '#theme' => 'user_profile_item' + ), ); }