Block weights reset for all blocks in a region breaks placement relative to other visibility groups

Created on 4 May 2017, over 7 years ago
Updated 27 February 2023, almost 2 years ago

Problem/Motivation

When using drag and drop to reorder blocks, all blocks in a region (not only a specific block that was moved) may be assigned a new weight. This works okay when only core is in play and a single form is used to reorder all blocks, since reassigned weights retain their relative ordering.

When editing only a specific block visibility group, however, the fact that all of that group's blocks may be assigned a new weight means that, while their internal ordering is okay, their ordering relative to blocks placed globally or via other block visibility groups may have changed.

Steps to reproduce

The problem arises from variations on the following steps:

  • Assign some sitewide blocks.
  • Create one or more block visibility groups and assign them blocks.
  • Bring up the main block layout page with "All blocks" selected for "Block Visibility Group". Note the relative ordering of blocks.
  • For "Block Visibility Group", select one of the groups you created previously. Add a new block and drag and drop it for ordering. Save.
  • Return to the main block layout page with "All blocks" selected for "Block Visibility Group". Result: not only the new block, but others as well may have shifted in relative position. Source of problem: weights for all blocks in the block visibility group were changed, so their position relative to other blocks on the site has changed.

Source of bug

The tabledrag behaviour leads to reassigned weights for all items in a group, not only the one that was dragged. Since they are not present on the form, blocks in different visibility groups retain their old weights, and so are out of order with the reordered ones.

Workaround

A workaround is: whenever using any block layout screen, ensure "Show row weights" has been selected before making any changes, so that all block ordering is done manually through explicitly selecting block weights.

Proposed resolution

Alter the block filtering such that all blocks are always on the form, though only ones for the current visibility group (and, if desired, global blocks) are visible. Thus, all blocks in a given region are re-weighted and so retain their relative order.

Remaining tasks

Fix up tests

For test coverage, we're drawing on the core test BookJavascriptTest::testBookOrdering()for its use of JS drag and drop.

See the handbook page PHPUnit Javascript testing tutorial β†’ for details on how to run JS tests.

Empty regions

Handling for the case that a given region has blocks but they're now all invisible. Need to change relevant class from 'region-populated' to 'region-empty'.

Optimizing?

::getEntityIds() may now be invoked multiple times and might need some caching.

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States oheller

Live updates comments and jobs are added and updated live.
  • Needs manual testing

    The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.

  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024