If a draggable list (like menu tree) has more than 100 items the weight field is converted from select to textfield. That's quite fine but if the users reorder the items by dragging (like most will do) the weights in the textfield are reset starting from the value of the first item in the list, incrementing it till the last item (not from the lowest value).
If I have 151 items in the list the weight will start from -50 and end on 100. That's also fine but If I drag the 151th item to the top, the weights will be reset and will start from 100 (the weight if the 151th item). Like this it will increment until max int(11) is reached which is the limit for the db column.
If the items are < 100 a select is used, which on the other hand loops over one select and gets all the possible weight values and resets all of them starting with the lowest possible and when the max is reached it repeats this max. Here is the code in tabledrag.js:

        if ($(targetElement).is('select')) {
          // Get a list of acceptable values.
          var values = [];
          $('option', targetElement).each(function () {
            values.push(this.value);
          });
          var maxVal = values[values.length - 1];
          // Populate the values in the siblings.
          $(targetClass, siblings).each(function () {
            // If there are more items than possible values, assign the maximum value to the row.
            if (values.length > 0) {
              this.value = values.shift();
            }
            else {
              this.value = maxVal;
            }
          });
        }
        else {
          // Assume a numeric input field.
          var weight = parseInt($(targetClass, siblings[0]).val(), 10) || 0;
          $(targetClass, siblings).each(function () {
            this.value = weight;
            weight++;
          });
        }

I think in case we have > 100 items the logic that the weights are reset starting from the lowest weight value should be preserved.

Comments

angel.h’s picture

Status: Active » Needs review
StatusFileSize
new676 bytes

Here is the patch.

angel.h’s picture

Shoot, I misspelled "infinite" in the patch name. :)

mgifford’s picture

Is this also a bug in Drupal 8?

pieterdc’s picture

Assigned: angel.h » Unassigned

Unassigning angel.h because he's not working on this at the moment.
Linking #1007746: Reordering fails with more than 100 items in a menu because it looks like that patch got more traction so far.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.