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

  1. Fix class typo by changing .js-indentations to .js-indentation
  2. Fix rowSettings.relationship === 'sibling' logic for the row variables

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

lauriii created an issue. See original summary.

lauriii’s picture

Status: Active » Needs review
StatusFileSize
new2.31 KB
bnjmnm’s picture

Status: Needs review » Reviewed & tested by the community

I confirmed that .js-indentations is not in use anymore. There is code that is no longer necessary as a result, and this patch correctly removes it.

xjm’s picture

Title: Remove dead code in tabledrag.js » Remove dead code in Claro's tabledrag.js
xjm’s picture

This seems only to be patching Claro. What about core/misc/tabledrag.es6.js? Is that deliberately excluded from the scope?

xjm’s picture

Status: Reviewed & tested by the community » Needs review
nod_’s picture

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 indentation in 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" and rowSettings.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.copyDragClasses function 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.

kristen pol’s picture

I'm trying to test this based on #7:

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.copyDragClasses function and check the classes being changed, when changing region, the wrong class is added to the dragged row.

Both with and without the patch, I checked:

targetElement[0].className = sourceElement[0].className;

when dragging a row on the Article Manage Display page page between regions.

I see the classes are set to:

field-weight form-text

and then:

js-field-parent field-parent form-select

But, the fix in the patch is related to changing js-indentations to js-indentation.

Any idea what I'm missing?

Screenshots:

lauriii’s picture

Based on #7, we should update the issue summary

nod_’s picture

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:

sourceElement[0].className: "block-region-select block-region-header form-select required"
targetElement[0].className: "block-region-select block-region-header form-select required"

The source element (source == what we copy FROM) has a class of block-region-header which is not correct, we just moved something to the pre-header region.

With the patch the result is:

sourceElement[0].className: "block-region-select block-region-pre_header form-select required"
targetElement[0].className: "block-region-select block-region-header form-select required"

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.

kristen pol’s picture

@nod_ Thanks for the details. I used the block layout page and dragged a block from Primary menu to Header.

After this code ran in Drupal.tableDrag.prototype.copyDragClasses:

    var sourceElement = $(sourceRow).find(".".concat(group));
    var targetElement = $(targetRow).find(".".concat(group));

The classes were:

  • sourceElement.className is block-region-select block-region-header form-select required"
  • targetElement.className is block-region-select block-region-primary_menu form-select required"

and after this code ran:

    if (sourceElement.length && targetElement.length) {
      targetElement[0].className = sourceElement[0].className;
    }

The classes were:

  • sourceElement.className is block-region-select block-region-header form-select required"
  • targetElement.className is block-region-select block-region-header form-select required"

This is inline with your example above.

kristen pol’s picture

Title: Remove dead code in Claro's tabledrag.js » Incorrect targetElement.className value when dragging table rows between regions
Issue summary: View changes
Issue tags: -Needs issue summary update

I made an attempt at updating the issue summary though I'm not sure it's clear.

kristen pol’s picture

Status: Needs review » Reviewed & tested by the community

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

kristen pol’s picture

Category: Task » Bug report
Issue tags: +Bug Smash Initiative

Adding tag as I worked on this yesterday for the Bug Smash Initiative.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Given the subtle-ness of this bug this looks worth adding an automated test for.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.