Problem/Motivation
The targetElement.className in Drupal.tableDrag.prototype.copyDragClasses in core/misc/tabledrag.js is incorrect when dragging rows from one region to another. Note that sourceElement.className is correct.
Example:
The targetElement.className classes for a block that is moved from the primary_menu region to a different region should be:
"block-region-select block-region-primary_menu form-select required"
Note the primary_menu in the block-region-primary_menu class.
Instead the class refers to the sourceElement.className value. For example, if you are moving a block from the primary_menuregion to the header region, the targetElement.className classes would incorrectly be set to:
"block-region-select block-region-header form-select required"
Note the header in the block-region-header class.
Per comment #7, the functionality has never worked.
Proposed resolution
- Fix class typo by changing
.js-indentationsto.js-indentation - Fix
rowSettings.relationship === 'sibling'logic for the row variables
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | Screen Shot 2020-05-29 at 1.19.49 PM.png | 103.84 KB | kristen pol |
| #8 | Screen Shot 2020-05-29 at 1.19.12 PM.png | 107.09 KB | kristen pol |
| #7 | core-js-tabledragindentation-3129871-7.patch | 5.35 KB | nod_ |
| #2 | 3129871-2.patch | 2.31 KB | lauriii |
Comments
Comment #2
lauriiiComment #3
bnjmnmI confirmed that
.js-indentationsis not in use anymore. There is code that is no longer necessary as a result, and this patch correctly removes it.Comment #4
xjmComment #5
xjmThis seems only to be patching Claro. What about
core/misc/tabledrag.es6.js? Is that deliberately excluded from the scope?Comment #6
xjmComment #7
nod_Was a bit of a rabbit hole, long story short: this is not dead code, it's code broken in several places. Attached patch seem to work as this whole thing was intended.
Turns out this code has never worked as intended because since the first commit #181066: Drag and drop of table rows (e.g. block admin) of the tabledrag there is an extra s after
indentationin the class name and I could not find any reference to it anywhere. This class was never generated and never used. On top of that the refacto and subsequent patch broke things again subtly #2489826: tabledrag is broken.It doesn't seem to affect anything, and is only triggered when using the mouse. since we save the page quickly after moving things I guess it was never an issue. Also the the combinaison of
rowSettings.relationship === "siblings"androwSettings.action !== "order"which could be problematic doesn't seem to happen anywhere I tested, so the problematic ifs and classnames have no consequences on important things.You can test on the manage block or manage display screen and dragging a row in between the different regions, using the debugger look into the
Drupal.tableDrag.prototype.copyDragClassesfunction and check the classes being changed, when changing region, the wrong class is added to the dragged row.With the attached patch things go as expected.
Comment #8
kristen polI'm trying to test this based on #7:
Both with and without the patch, I checked:
when dragging a row on the Article Manage Display page page between regions.
I see the classes are set to:
and then:
But, the fix in the patch is related to changing
js-indentationstojs-indentation.Any idea what I'm missing?
Screenshots:
Comment #9
lauriiiBased on #7, we should update the issue summary
Comment #10
nod_Sorry Kristen Pol, a bit late but here it is:
On the block admin page (i'm using umami), when moving a row from one region (header) to another (pre-header) and we look at the source and target classes we can see:
The source element (source == what we copy FROM) has a class of
block-region-headerwhich is not correct, we just moved something to the pre-header region.With the patch the result is:
we selected the proper row to copy classes from.
The code tries to figure out the closest sibling and copy the classes. Siblings can be because of a "group" (like the theme regions) but it can also mean the same depth level, which is where we need the indentation thing to be working as expected.
Comment #11
kristen pol@nod_ Thanks for the details. I used the block layout page and dragged a block from
Primary menutoHeader.After this code ran in
Drupal.tableDrag.prototype.copyDragClasses:The classes were:
block-region-select block-region-header form-select required"block-region-select block-region-primary_menu form-select required"and after this code ran:
The classes were:
block-region-select block-region-header form-select required"block-region-select block-region-header form-select required"This is inline with your example above.
Comment #12
kristen polI made an attempt at updating the issue summary though I'm not sure it's clear.
Comment #13
kristen polAssuming the issue summary is ok (or someone can fix it better than me), this seems RTBC to me. The changes are straightforward and it passes manual testing and automated testing.
Comment #14
kristen polAdding tag as I worked on this yesterday for the Bug Smash Initiative.
Comment #15
alexpottGiven the subtle-ness of this bug this looks worth adding an automated test for.