As the title says, anyway to increase the granularity of the weight range? It is quite limiting, and hard to use compared to some other CMS.
Values from -100/100 would be useful.

Is this something that can be changed site wide? Or is it module specific?

Comments

mango’s picture

I agree. When creating custom content types with many fields, it is impossible to order the fields properly as there are more fields than weights available.

Andreas Wolf’s picture

Due to the "Personal battle plans for Drupal 6" http://drupal.org/node/111140, quicksketch is planning "to work on jQuery based weights in tables (drag and drop). Finally we'll be able to rid ourselves of the awkward 'change the weight, refresh the page' workflow we've been using for so long."

Steve McKenzie also announced to work on "Drag n Drop for Core (Weight Value sorting on Menus, Taxonomy, Blocks, Profile Fields and region sorting on Blocks)."

Maybe this could help your needs.

mango’s picture

Drag and Drop for Core would be great. I guess we will just have to wait for Drupal 6 to come out, make ado and be patient for a while.

Chill35’s picture

In the meantime, where in Drupal's core code can these limits -10, +10 be changed ?

Are these hard-coded on a per module basis ?

Caroline
11 heavens

deevio’s picture

I'm pretty new to Drupal myself so I don't quite know the ins and outs of it just yet.

There's probably an easier way to get this done..but here's my solution. More of a hack really...

I added a line inside function process_weight($element) found in line 1488 of the core file: includes/form.inc

add this line before the for($n= (-1 ... ) loop:

$element['#delta'] = 100;  // or whatever range you want. this sets the limits to -100, +100

Hope this helps...

christosk’s picture

I used your hack and used it to sort fields in a custom content type and at first it seemed to work fine (more weight options available) but after updating the fileds' weights in fields management, fields with weight more than 10 disapeared from the list! The fields were not lost of course, they just don't show up in that list.
Furthermore, while adding content of this content type the fields with high weights seem to get mixed up with the default form items that are present at the bottom of the page (Comment settings, menu settings, etc). Maybe the reason drupal limits the custom weights from -10 to 10 is to leave space for default or module created items.
To recover i hade to change the weights manualy in the node_field_instance table

hipfox’s picture

Hmmm, it seems a quick way that increase site-wide weight range. My poor way to hack taxonomy.module, just need to extend term weight.

- line 421

  $form['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#default_value' => $edit['weight'],
+    '#delta' => 100,
    '#description' => t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.'));

Have any good idea to do?

timoratd’s picture

we are using book module on our site, as you all know, some books have more than 31 chapters 8-(

barnamala’s picture

In books module weight field is tinyint which supports -128 to +127

What you need to do is make some small cjange in "book.module" file available "module/book" folder.

*Hints-

Opne the file and change all instance of " '#delta' => 15 " to " '#delta' => 127 "

That will bring a weight range -127 to +127

Thats all. works fine for me.

-Barnamala

bassplaya’s picture

does this mean it can be done for all the other modules as well with the same kind of hack? (4.7)

Authentically,
BassPlaya

dwrunyon’s picture

Very simple and worked beautifully... thank you VERY much!

mnoyes’s picture

Just to let people know that this fix still works as of 12/2009 in Drupal 6. Thanks! This really should be a setting administrators/users can change without editing the book.module file.

jsimonis’s picture

When I've needed more, the only option I could find was to go in and manually edit the module.

I have only done this on the forms module (for 4.7 and earlier), so I can't tell you off hand where to find it in the other modules.

--
Jenni S.

bassplaya’s picture

I'll give it a try and let you know.. thanx for the reply !!

Authentically,
BassPlaya

Zoologico’s picture

Hi folks,

Very interesting discussion here.
Anyone figure out a way to make these weights be more versatile?

bassplaya’s picture

I can't find the delta thing in for example the node.module and the word weight is there a 100 times.. I really don't know which one is responsible for the range of the weight. Hope someone else can find out.

Authentically,
BassPlaya

vm’s picture

weights can be extended using the weight.module in the downloads area.

Devis’s picture

interesting topic
very strange that this isn't fixed yet

--
Italian drupaler

tseven’s picture

I used both patches posted above, but to clarify I will repeat the code modifications with a bit more info.

  1. Find this code around line 1494 in /includes/form.inc:

    function process_weight($element) {
      for ($n = (-1 * $element['#delta']); $n <= $element['#delta']; $n++) {
        $weights[$n] = $n;
      }
      $element['#options'] = $weights;
      $element['#type'] = 'select';
      $element['#is_weight'] = TRUE;
      return $element;
    }
    

    and replace/modify to match this:

    function process_weight($element) {
      $element['#delta'] = 100; //Change this value to whatever you like 
      for ($n = (-1 * $element['#delta']); $n <= $element['#delta']; $n++) {
        $weights[$n] = $n;
      }
      $element['#options'] = $weights;
      $element['#type'] = 'select';
      $element['#is_weight'] = TRUE;
      return $element;
    }
    
  2. Find this code around line 440 in /modules/taxonomy/taxonomy.module
    $form['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight'),
      '#default_value' => $edit['weight'],
      '#description' => t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.'));
    

    and replace/modify it to match:

    $form['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight'),
      '#default_value' => $edit['weight'],
      '#delta' => 100, //Change this number to the value you chose in step 1
      '#description' => t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.'));
    
  3. Find this code around line 175 in /modules/cck/content_admin.inc
    if (is_array($value) && (isset($value['#weight']) || $key == 'body_filter') && $value['#weight'] <= 10) {
    

    and replace/modify to match:

    if (is_array($value) && (isset($value['#weight']) || $key == 'body_filter') && $value['#weight'] <= 100) {
    

    Notice the value at the end,.. I changed from 10 to 100,.. so that all the fields and groups with a weight higher than 10 will be shown when editing them.

Final Step

Here comes the tricky part.

You will probably need to change all the default weight values to something higher.

I downloaded my entire web dir and opened it in TextMate (a powerful text editor for the mac, Ultra Edit works well for windows) and did a global search & replace.

I searched for: '#weight' => 25 and replaced with: '#weight' => 65 adding 40 to the initial weight. You must do this for all the default values.

I would suggest starting at the highest weight value: 100 and working your way down so you don't enter an infinite loop :). I found that 100 was used as the maximum and it seemed to skip the range until 50. You don't need to search for every incremental value, but the key ones seem to be numbers divisible by 5 (25, 30 etc) and numbers ending in 9.

Be careful modifying weights around and below 10. I'd suggest doing this on a per instance basis.

Oh and of course, always backup your code before changing -anything- :)

pelicani’s picture

There is an easier way, built into drupal, to allow you to increase your weighting list.
And can be implemented per each form if desires.

Create a new module and add this function...

function <modulename>_form_alter($form_id, &$form) {
	if ($form_id == "taxonomy_form_term") {
		$form['weight']['#delta'] = 33;
	}
}

Change the <modulename> with the name of your module and this will increase the weight limits from 10 to 33.

Web Developer : RockRiverStar.com : Philadelphia, PA

Technical Architect : Philadelphia, PA

Tamar Badichi-Levy’s picture

I have added you code but nothing happens to the weight limits.
I tried to set the $form_id to the cck type form id. I also tried without the if statement...
The $form['weight']['#delta'] is being set but nothing happens

zbricoleur’s picture

Changed line 72 of system.module from

  $type['weight'] = array('#input' => TRUE, '#delta' => 10, '#default_value' => 0, '#process' => array('process_weight' => array()));

to:

  $type['weight'] = array('#input' => TRUE, '#delta' => 20, '#default_value' => 0, '#process' => array('process_weight' => array()));

This is a global change to the delta, affecting all 'weight' inputs in all forms, but as far as I'm concerned, that's a good thing.
I've tested it a bit, and it does rearrange the form as I think it should, and the display mirrors the form order. No adverse effects that I've noticed; I will post back here if I see any.
I can imagine it might cause some problems if you ever decided in the future to lowerthe delta. Along the same lines, if you forgot to bring this hack forward when you upgraded to 6 or 7, I imagine there might be a price to pay.

scottrigby’s picture

iyan’s picture

Thanks zbricoleur, It works well for me! (i'm using 5.7 too)

whisk’s picture

Wrote a tiny module. Hope it could help.

http://remarka.ru/drupal/weight_range-5.x-0.1.tar

TheSmegHead’s picture

I installed and enabled your module, but I cannot figure out how it works. How do you set a new weight range?

edit: never mind, the module automatically extends the weight range as soon as it is enabled: -30 to +30, and works prefectly. I expect you could change the number 3 in this line for a larger range: $element['#delta'] = $element['#delta'] * 3

Thanks!

herchenx’s picture

@whisk, this is a great example of a simple module that is very useful (for 5.x sites)

Thank you for making this available. It works great.

suro.solutions’s picture

It Added the weights. But When I submitted the form all the fields got disappeared.

ressa’s picture

I tried one of the above tips increasing the range from 10 to 30, but it didn't work in CCK. If I selected for example weight 12 the field wouldn't show up under Home » Administer » Content management » Content types » Manage fields

It turns out the simple solution and working _with_ Drupal is the way to do it 8o)

Just remember to configure how fields and field labels should be displayed when it's viewed in teaser and full-page mode under "Display fields" before you group them, since they are locked when grouped.

Anonymous’s picture

Can anyone point me to a solution for drupal 6?
i need it to set the right order for cck fields in a views 2 view with more than 50 fields.

benstallings’s picture

I was able to get the weight_range module above working in Drupal 6 by making the following changes:

In weight_range.info, define

core = 6.x
php = 5.0

In weight_range.module, change line 9 to

'#process' => 'weight_range_process_weight'

Enjoy!

benstallings’s picture

Here is a working copy of the Drupal 6 module, complete with admin settings screen. I've applied for a CVS account so I can contribute it properly.
http://interdependentweb.com/weight_range.zip

Anonymous’s picture

sounds good, will try it now.

Edit: Works perfect. just it does not show me an option in the menu, but the url is not easy to find when i look into the module.

mrfelton’s picture

Works for me. Nice one.

--
Tom
www.systemseed.com - drupal development. drupal training. drupal support.

hefox’s picture

Typo in your hook_menu, MENU_NORMAL_ITEM not MENU_LOCAL_TASK.

Did ya ever get a CVS account for this?

bevin’s picture

thank u so much. It works for me

sunil_datta’s picture

opened modules/book/book.module at line 389 '#delta' => 15 I changed the value to 100 and it worked.

sunil datta
www.opensourcenuts.com

tarzadon’s picture

@sunil_datta's suggestion works, but only in the drop-down menu. The drag and drop function of reordering still won't reorder the pages.

marlonleandropereira’s picture

Exist default range of weight to modules?

If yes, what's the default range of Weight? -100 and 100?