Need bigger weight range!

littleprince - February 8, 2007 - 20:46

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?

Totally agree

mango - February 8, 2007 - 21:08

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.

No more weights

Andreas Wolf - February 8, 2007 - 23:26

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.

Drag and Drop for Core would be great

mango - February 9, 2007 - 08:39

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.

Using Drupal 6 for a production site is not for tomorrow

Chill35 - February 9, 2007 - 08:55

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

re: where in Drupal's core code can these limits -10, +10

deevio - March 16, 2007 - 07:22

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...

re: where in Drupal's core code can these limits -10, +10

christosk - April 2, 2007 - 02:42

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

Hmmm, it seems a quick way

Hipfox - April 17, 2007 - 15:55

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?

Agree with weight increasing

tutube - February 28, 2007 - 18:57

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

Weight Range can be extended in Book module

barnamala - June 29, 2007 - 11:42

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

so it can be done?

BassPlaya - August 15, 2007 - 09:50

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

Very simple and worked

dwrunyon - April 3, 2008 - 04:42

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

Edit the module

jsimonis - March 16, 2007 - 09:22

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.

ok

BassPlaya - August 17, 2007 - 06:27

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

Anyone figure this out?

Zoologico - December 7, 2007 - 17:41

Hi folks,

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

can't find delta tag..

BassPlaya - January 13, 2008 - 16:40

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.

=-=

VeryMisunderstood - January 13, 2008 - 16:43

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

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

subscribed

Devis - January 12, 2008 - 02:11

interesting topic
very strange that this isn't fixed yet

--
Italian drupaler

This is what I did...

tseven - January 24, 2008 - 08:38

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- :)

another way

pelicani - April 1, 2008 - 20:22

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

this code does not work for me

levyofi - April 15, 2008 - 18:48

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

So far, this works for me in 5.7

zbricoleur - April 16, 2008 - 15:43

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.

following...

scottrigby - April 17, 2008 - 18:42

following this thread - thx

Works for me

iyan - April 23, 2008 - 03:58

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

A tiny helper module

whisk - July 31, 2008 - 13:01

Wrote a tiny module. Hope it could help.

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

I installed and enabled your

TheSmegHead - August 2, 2008 - 22:42

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!

Use Groups to group your fields

ressa - August 22, 2008 - 14:33

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.

 
 

Drupal is a registered trademark of Dries Buytaert.