From 8c02d4ec93b1af107dbd43ccb460c08a22e78675 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 20 Jan 2006 09:04:34 +0000 Subject: - Patch #45530 by Morbus: filter_form shouldn't default to #weight 0 When a form element doesn't specify a #weight, it is assumed internally as #weight 0. However, to ensure that our form elements display visually *as they were defined in the array* we, in form_builder, count the number of elements, divide by 1000, and set that as the weight: # Assign a decimal placeholder weight to preserve original array order if (!isset($form[$key]['#weight'])) { $form[$key]['#weight'] = $count/1000; } The above code will set the #weights of elements that have not defined a weight to something like 0 (first element in array definition), 0.001, 0.002, and so on. However, anytime a form element *explicitly* defines a #weight of 0, that #weight is kept at exactly 0, which would cause that form element to appear BEFORE the elements that didn't have a #weight defined (and thus received a #weight such as 0.002). Consider the following pseudo example: $form['game_title'] = array( '#type' => 'textfield', ... ); $form['game_description'] = array( '#type' => 'textarea', ... ); $form['game_format'] = filter_form(variable_get('game_format', NULL)); return $form; Here, we're not definiing weights on our two textfields. We then add an filter_form. The second parameter of the filter_form is $weight, which defaults to 0. After this $form hits form_builder, we have weights 0 (game_title), 0.001 (game_description), and 0 (filter_form) respectively. This is then sorted by weight, which causes filter_form (the third element in the array) to appear BEFORE game_description (0 is lighter than 0.001). The short lesson is: explicitly defining #weight 0 for a form element is probably a bad idea. This patch changes the default #weight of filter_form to NULL, instead of 0, and also removes any other explicit setting of #weight to 0 in core. --- modules/block.module | 3 --- modules/block/block.module | 3 --- modules/blog.module | 2 +- modules/blog/blog.module | 2 +- modules/book.module | 2 +- modules/book/book.module | 2 +- modules/comment.module | 4 +--- modules/comment/comment.module | 4 +--- modules/filter.module | 2 +- modules/filter/filter.module | 2 +- modules/forum.module | 2 +- modules/forum/forum.module | 2 +- modules/node.module | 3 --- modules/node/node.module | 3 --- modules/page.module | 2 +- modules/page/page.module | 2 +- modules/story.module | 2 +- modules/story/story.module | 2 +- modules/user.module | 2 +- modules/user/user.module | 2 +- 20 files changed, 16 insertions(+), 32 deletions(-) (limited to 'modules') diff --git a/modules/block.module b/modules/block.module index e97187483..58c66515d 100644 --- a/modules/block.module +++ b/modules/block.module @@ -325,7 +325,6 @@ function block_admin_configure($module = NULL, $delta = 0) { '#type' => 'fieldset', '#title' => t('Block specific settings'), '#collapsible' => true, - '#weight' => 0, ); foreach ($settings as $k => $v) { @@ -343,7 +342,6 @@ function block_admin_configure($module = NULL, $delta = 0) { '#type' => 'fieldset', '#title' => t('User specific visibility settings'), '#collapsible' => true, - '#weight' => 0, ); $form['user_vis_settings']['custom'] = array( '#type' => 'radios', @@ -355,7 +353,6 @@ function block_admin_configure($module = NULL, $delta = 0) { '#type' => 'fieldset', '#title' => t('Page specific visibility settings'), '#collapsible' => true, - '#weight' => 0, ); $access = user_access('use PHP for block visibility'); diff --git a/modules/block/block.module b/modules/block/block.module index e97187483..58c66515d 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -325,7 +325,6 @@ function block_admin_configure($module = NULL, $delta = 0) { '#type' => 'fieldset', '#title' => t('Block specific settings'), '#collapsible' => true, - '#weight' => 0, ); foreach ($settings as $k => $v) { @@ -343,7 +342,6 @@ function block_admin_configure($module = NULL, $delta = 0) { '#type' => 'fieldset', '#title' => t('User specific visibility settings'), '#collapsible' => true, - '#weight' => 0, ); $form['user_vis_settings']['custom'] = array( '#type' => 'radios', @@ -355,7 +353,6 @@ function block_admin_configure($module = NULL, $delta = 0) { '#type' => 'fieldset', '#title' => t('Page specific visibility settings'), '#collapsible' => true, - '#weight' => 0, ); $access = user_access('use PHP for block visibility'); diff --git a/modules/blog.module b/modules/blog.module index 1dd5df58b..b8a2c9204 100644 --- a/modules/blog.module +++ b/modules/blog.module @@ -230,7 +230,7 @@ function blog_form(&$node) { $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['filter'] = filter_form($node->format, 1); + $form['body_filter']['filter'] = filter_form($node->format); return $form; } diff --git a/modules/blog/blog.module b/modules/blog/blog.module index 1dd5df58b..b8a2c9204 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -230,7 +230,7 @@ function blog_form(&$node) { $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['filter'] = filter_form($node->format, 1); + $form['body_filter']['filter'] = filter_form($node->format); return $form; } diff --git a/modules/book.module b/modules/book.module index 3354c8656..60ec8cc15 100644 --- a/modules/book.module +++ b/modules/book.module @@ -253,7 +253,7 @@ function book_form(&$node) { $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['format'] = filter_form($node->format, 1); + $form['body_filter']['format'] = filter_form($node->format); $form['log'] = array( '#type' => 'textarea', '#title' => t('Log message'), '#default_value' => $node->log, '#weight' => 5, diff --git a/modules/book/book.module b/modules/book/book.module index 3354c8656..60ec8cc15 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -253,7 +253,7 @@ function book_form(&$node) { $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['format'] = filter_form($node->format, 1); + $form['body_filter']['format'] = filter_form($node->format); $form['log'] = array( '#type' => 'textarea', '#title' => t('Log message'), '#default_value' => $node->log, '#weight' => 5, diff --git a/modules/comment.module b/modules/comment.module index 18e8b304d..cadac359f 100644 --- a/modules/comment.module +++ b/modules/comment.module @@ -343,7 +343,6 @@ function comment_configure() { '#title' => t('Viewing options'), '#collapsible' => TRUE, '#collapsed' => TRUE, - '#weight' => 0, ); $form['viewing_options']['comment_default_mode'] = array( @@ -387,7 +386,6 @@ function comment_configure() { '#title' => t('Posting settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, - '#weight' => 0, ); $form['posting_settings']['comment_anonymous'] = array( @@ -1333,7 +1331,7 @@ function comment_form($edit, $title = NULL) { } $form['comment_filter']['comment'] = array('#type' => 'textarea', '#title' => t('Comment'), '#rows' => 15, '#default_value' => $edit['comment'] ? $edit['comment'] : $user->signature, '#required' => TRUE); - $form['comment_filter']['format'] = filter_form($edit['format'], 1); + $form['comment_filter']['format'] = filter_form($edit['format']); $form['cid'] = array('#type' => 'value', '#value' => $edit['cid']); $form['pid'] = array('#type' => 'value', '#value' => $edit['pid']); diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 18e8b304d..cadac359f 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -343,7 +343,6 @@ function comment_configure() { '#title' => t('Viewing options'), '#collapsible' => TRUE, '#collapsed' => TRUE, - '#weight' => 0, ); $form['viewing_options']['comment_default_mode'] = array( @@ -387,7 +386,6 @@ function comment_configure() { '#title' => t('Posting settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, - '#weight' => 0, ); $form['posting_settings']['comment_anonymous'] = array( @@ -1333,7 +1331,7 @@ function comment_form($edit, $title = NULL) { } $form['comment_filter']['comment'] = array('#type' => 'textarea', '#title' => t('Comment'), '#rows' => 15, '#default_value' => $edit['comment'] ? $edit['comment'] : $user->signature, '#required' => TRUE); - $form['comment_filter']['format'] = filter_form($edit['format'], 1); + $form['comment_filter']['format'] = filter_form($edit['format']); $form['cid'] = array('#type' => 'value', '#value' => $edit['cid']); $form['pid'] = array('#type' => 'value', '#value' => $edit['pid']); diff --git a/modules/filter.module b/modules/filter.module index 75ecff13d..1a62d8518 100644 --- a/modules/filter.module +++ b/modules/filter.module @@ -750,7 +750,7 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) { * @return * HTML for the form element. */ -function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = 0, $parents = array('format')) { +function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) { if ($value == FILTER_FORMAT_DEFAULT) { $value = variable_get('filter_default_format', 1); } diff --git a/modules/filter/filter.module b/modules/filter/filter.module index 75ecff13d..1a62d8518 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -750,7 +750,7 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $check = TRUE) { * @return * HTML for the form element. */ -function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = 0, $parents = array('format')) { +function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) { if ($value == FILTER_FORMAT_DEFAULT) { $value = variable_get('filter_default_format', 1); } diff --git a/modules/forum.module b/modules/forum.module index 7db151472..c5cb96979 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -593,7 +593,7 @@ function forum_form(&$node) { } $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['format'] = filter_form($node->format, 1); + $form['body_filter']['format'] = filter_form($node->format); return $form; } diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 7db151472..c5cb96979 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -593,7 +593,7 @@ function forum_form(&$node) { } $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['format'] = filter_form($node->format, 1); + $form['body_filter']['format'] = filter_form($node->format); return $form; } diff --git a/modules/node.module b/modules/node.module index 02e404375..6ab226562 100644 --- a/modules/node.module +++ b/modules/node.module @@ -1632,9 +1632,6 @@ function node_form_array($node) { if (!isset($form['title']['#weight'])) { $form['title']['#weight'] = -5; } - if (!isset($form['body']['#weight'])) { - $form['body']['#weight'] = 0; - } // If this is a new node, fill in the default values. $node_options = variable_get('node_options_'. $node->type, array('status', 'promote')); diff --git a/modules/node/node.module b/modules/node/node.module index 02e404375..6ab226562 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1632,9 +1632,6 @@ function node_form_array($node) { if (!isset($form['title']['#weight'])) { $form['title']['#weight'] = -5; } - if (!isset($form['body']['#weight'])) { - $form['body']['#weight'] = 0; - } // If this is a new node, fill in the default values. $node_options = variable_get('node_options_'. $node->type, array('status', 'promote')); diff --git a/modules/page.module b/modules/page.module index 22eebc1cb..92b5469b8 100644 --- a/modules/page.module +++ b/modules/page.module @@ -94,7 +94,7 @@ function page_form(&$node) { $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['format'] = filter_form($node->format, 1); + $form['body_filter']['format'] = filter_form($node->format); $form['log'] = array( '#type' => 'textarea', '#title' => t('Log message'), '#default_value' => $node->log, '#weight' => 5, diff --git a/modules/page/page.module b/modules/page/page.module index 22eebc1cb..92b5469b8 100644 --- a/modules/page/page.module +++ b/modules/page/page.module @@ -94,7 +94,7 @@ function page_form(&$node) { $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['format'] = filter_form($node->format, 1); + $form['body_filter']['format'] = filter_form($node->format); $form['log'] = array( '#type' => 'textarea', '#title' => t('Log message'), '#default_value' => $node->log, '#weight' => 5, diff --git a/modules/story.module b/modules/story.module index 2f1887e62..5221db6d1 100644 --- a/modules/story.module +++ b/modules/story.module @@ -87,7 +87,7 @@ function story_validate($node) { function story_form(&$node) { $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['format'] = filter_form($node->format, 1); + $form['body_filter']['format'] = filter_form($node->format); return $form; } diff --git a/modules/story/story.module b/modules/story/story.module index 2f1887e62..5221db6d1 100644 --- a/modules/story/story.module +++ b/modules/story/story.module @@ -87,7 +87,7 @@ function story_validate($node) { function story_form(&$node) { $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['format'] = filter_form($node->format, 1); + $form['body_filter']['format'] = filter_form($node->format); return $form; } diff --git a/modules/user.module b/modules/user.module index c128c46ea..aefa1aea5 100644 --- a/modules/user.module +++ b/modules/user.module @@ -1170,7 +1170,7 @@ function user_register_submit($form_id, $form_values) { function user_edit_form($uid, $edit) { // Account information: - $form['account'] = array('#type' => 'fieldset', '#title' => t('Account information'), '#weight' => 0); + $form['account'] = array('#type' => 'fieldset', '#title' => t('Account information')); if (user_access('change own username') || user_access('administer users')) { $form['account']['name'] = array('#type' => 'textfield', '#title' => t('Username'), '#default_value' => $edit['name'], '#maxlength' => 55, '#description' => t('Your full name or your preferred username: only letters, numbers and spaces are allowed.'), '#required' => TRUE); } diff --git a/modules/user/user.module b/modules/user/user.module index c128c46ea..aefa1aea5 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1170,7 +1170,7 @@ function user_register_submit($form_id, $form_values) { function user_edit_form($uid, $edit) { // Account information: - $form['account'] = array('#type' => 'fieldset', '#title' => t('Account information'), '#weight' => 0); + $form['account'] = array('#type' => 'fieldset', '#title' => t('Account information')); if (user_access('change own username') || user_access('administer users')) { $form['account']['name'] = array('#type' => 'textfield', '#title' => t('Username'), '#default_value' => $edit['name'], '#maxlength' => 55, '#description' => t('Your full name or your preferred username: only letters, numbers and spaces are allowed.'), '#required' => TRUE); } -- cgit v1.2.3