The blocks admin form is generated by If a block is deleted then the calculated value of $weight_delta (the "delta" value for the weights dropdown) will as often as not be reduced. However the actual block weights are not altered. This can result in blocks having invalid weights (#default_value) in the form definition.

Example: Suppose we have 40 blocks and delete one, so that $weight_delta is now 19. Since the first block in each region will (if dabledrag has been used) have weight -20, no value is output for the "weight" select element in the form. In most browsers this seems to result in the first option in the select being selected (i.e. -19). Hence 2 blocks in each region will now have the same weight.

The end result is that the blocks at the top of each region will start mysteriously re-arranging themselves.

This can be compounded by #565184: Blocks can be displayed in different order from that shown on blocks admin page.


gpk’s picture

Component: blog.module » block.module

For info: $weight_delta was introduced in #293370: Block sort / reorder fails if more than 20 items.

Also correcting Component.

MtRoxx’s picture

I seem to be having this issue as well. When I try to move blocks, they jump around to other menus.

brad.bulger’s picture

I am not sure if this should go here, on to the related ticket, or a new issue, but I am seeing a pretty basic problem: the "weight" column in the blocks table is a tinyint. and on mysql at least, the maximum range of a tinyint is -128 to 128. but if you have more than 256 blocks, as we do, it tries to set a weight to values way outside that range, because $weight_delta is based on the total count of blocks. when they're saved to the db, it silently knocks them all back to the lower or upper bound. moving blocks around with drag and drop can result in all the blocks being set to a weight of -128. i don't see any further finer level values being stored anywhere, so it sure looks like the block order would be, what, alphabetical at that point? or by module and then delta?

gpk’s picture

@3: sounds like a different problem. Suggest you open a new issue if there isn't already one for your problem.

Neil C Smith’s picture

Version: 6.13 » 7.31
Priority: Normal » Critical
Issue summary: View changes

This issue is still in 7.31, just as described in the original summary. I recently disabled a number of now unused views on a long running site, which removed about 20 different blocks. This reduced the available deltas causing almost all the blocks to be assigned the same minimum delta on the block admin page, and thus all block orders to be completely randomized across the site when saved.

Marked up as critical since this is in effect data loss - there is no way to restore the old block ordering without reverting to a database backup or manually reconfiguring.

cilefen’s picture

Please check if this is a bug in Drupal 8. If so, the issue must be moved to the Drupal 8 queue and fixed there first according to the backport policy. If it is relevant to Drupal 8, move it to branch 8.0.x-dev and tag it “Needs backport to D7”.
There may also be an existing Drupal 8 issue. Try to find it. If one exists, tag it “Needs backport to D7” and mark this issue “Closed: duplicate”. If the Drupal 8 issue is open, you may offer a patch. If its status is “Fixed”, make its status “Patch (to be ported)”, move it to version 7.x-dev and upload your latest patch if you have one.

david.soendergaard’s picture

I can confirm that this is still a problem in Drupal 8.2.3.

When reordering the blocks, it will start the weight on -$delta_weight+1 for all the weights.
This weight will be constant when deleting blocks, except that when deleting more 3+ blocks, the top blocks will all start getting the same weight, until we hit the new $delta_weight

GiorgosK’s picture

Version: 7.31 » 8.2.6

its the seconds report (together with the 1 above) that this happened to

there was no problem before but after deleting 2 blocks and then tried to put them back the orders withing regions get screwed up
and end up in different positions than I intend to put them

if you make the weight visible after saving all blocks have the same weight "-32" and "-32" is the smallest number I can choose
NOTE there are 64 blocks active on the drupal installation

blocks can be placed on their right places using weights (not with drag and drop) but as soon as I drag/drop is enabled again and I save the blocks they change positions

I will report back with more findings

GiorgosK’s picture

Status: Active » Postponed (maintainer needs more info)

upon further investigation at least in our situation it was caused by a badly behaving admin theme

if more people have other reports please change the status

sassafrass’s picture

Status: Postponed (maintainer needs more info) » Active

Blocks mysteriously reorder for me. I am using D8.3.2 It seems to happen more often when using the drag and drop, rather than when using the weights...but it does happen at other times that users have reported editing blocks that are in the block layout page. More often than not, the Title block and the Tab block end up at the bottom of most pages and the rest of the blocks maintain their order, but not their weights. All weights are reassigned to be sequential. No blocks can seem to have the same weight.

sassafrass’s picture

Also... I have only experienced this in the Content Region.

catch’s picture

@sassafrass the original bug report here was only about weights being changed on block deletion. If you're getting unexpected behaviour when editing rather than deleting, would you mind opening a new issue and linking to it from this one?