diff options
author | Dries Buytaert <dries@buytaert.net> | 2006-01-20 09:04:34 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2006-01-20 09:04:34 +0000 |
commit | 8c02d4ec93b1af107dbd43ccb460c08a22e78675 (patch) | |
tree | 3865301030667dbd3a93fa7f921ace69ce34cac7 /modules/block | |
parent | 4a7abb95b69159bd7f16d98106ead78315e97d29 (diff) | |
download | brdo-8c02d4ec93b1af107dbd43ccb460c08a22e78675.tar.gz brdo-8c02d4ec93b1af107dbd43ccb460c08a22e78675.tar.bz2 |
- 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.
Diffstat (limited to 'modules/block')
-rw-r--r-- | modules/block/block.module | 3 |
1 files changed, 0 insertions, 3 deletions
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'); |