When the max depth is set to 2 or more levels, the tree renders all of the values irrespective of the depth, and when a value is clicked, the depth of that value is automatically adjusted to the set max depth. This is perfect.

IE: Two levels allowed, but three are rendered.
a
--b
----c
User clicks c
a
--b
--c

But at the max depth, passing 0 as the depth, the desired / expected behavior when the user clicks a item deeper than the first level, it should fallback to the root level
a
--b
c (was ----c)

But the tree actually allows any level to be rendered, which is the bug.

Using -1 as the depth limiter appears to work nicely

Comments

xjm’s picture

Thanks for the patch. The code looks straightforward to me.

Before/after manual testing and screenshots would be good here. To that end, it would be good to have steps to reproduce, including dummy code if needed. Tagging as novice for that.

xjm’s picture

StatusFileSize
new2.22 KB

Oh, here's a reroll for core/.

nod_’s picture

Status: Needs review » Needs work

It sounds to me like it's doing what it's supposed to. If you count from 0, depth = 2 will give you three levels. does depth = 1 gives the expected behavior? Or am I missing something here?

chrisshattuck’s picture

I played for a while in the UI with some different places where drupal_add_tabledrag() is used - in the book and menu interface - and don't quite understand where the problem is. I'd be happy to add some screenshots to explain what's going on and do some testing if I had an example of where this occurs. Thanks!

lokapujya’s picture

Issue summary: View changes
Issue tags: +Needs reroll

Seems like maxDepth of 0 (which is the default) means no max depth. So, this patch changes the default to -1 and then uses -1 to mean "no max depth" and intends to use 0 to mean that no children levels are allowed.

I added some book pages and played around with the maxDepth on the book module at admin/structure/book/. But, no child levels for Book doesn't make sense. Is there a use case where a drupal_add_tabledrag() with no child levels?

nod_’s picture

block admin page

alan d.’s picture

StatusFileSize
new6.96 KB
new7.52 KB
new4.42 KB
new3.51 KB
new3.17 KB

Um.... this was not a book issue, it was a table drag issue.

Discovered when playing with the sandbox project https://drupal.org/sandbox/aland/1311114 Very specific use-case. Firstly the motive for this module was to have a taxonomy like system that could handle the geoname dataset - all 5 million records. (Try taxonomy post 10,000 or so records and watch your site die...)

Disclaimer, this sandbox has had no love in years, it throws notices on install, but appears to be functional still.

Each country has a set number of allowed sub-regions and this determines the max length, for AG there are 4 by default and this is what the screenshots reflect.

Added some regions to play with

Dragging them around, max depth is 4, no issues

On save, the child regions are hidden in the tree after two levels (just in case you try this out and go wtf...). This bypasses the memory limits both server side and client side with large dnd tables

Clicking a-a

Depth limited to 2, no issues. i.e we are already 2 levels deep (a, a-a)

Click list regions on a-a-a

We are currently on the 4th level. So no nesting allowed and the sets the depth parameter to limit it 0, however you can happily drag to any depth.

alan d.’s picture

Issue tags: -Needs reroll
StatusFileSize
new2.33 KB
alan d.’s picture

Status: Needs work » Needs review
alan d.’s picture

StatusFileSize
new13.49 KB
new6.02 KB
new12.29 KB

I guess to address the above question more clearly, to allow this function to handle dynamic data where depth is potentially anything form 0 to xyz. Say a contrib module that limits the depth of a menu, many themes use a flat level menu, other menus at 2 level, etc, and you want to also limit this on the admin pages. Overrides theme_menu_overview_form() as well as other functions and sets the configuration to only to allow 'what_ever_this_is_in_drupal_8_again' to 1 [sorry, forgetting the config manager stuff atm), so $limit = 0 is passed to drupal_add_tabledrag()

drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, variable_get('what_ever_this_is_in_drupal_8_again', MENU_MAX_DEPTH) - 1);

A usable manual test procedure without pain for Drupal 8.x, say MENU_MAX_DEPTH was configurable, and then set to 1. (BTW, it's not and things blow up if you play with this constant). So update theme_menu_overview_form() to set the depth at 0 to mimic this.

- drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1);
+ drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, 0);

Edit a menu with items - http://drupal/admin/structure/menu/manage/account

Prior to the patch

You can nest the links

Post patch

Limited to a vertical dragging only.

Revert the 0 to MENU_MAX_DEPTH - 1 and edit the main administration menu and dnd to your hearts content.

http://drupal/admin/structure/menu/manage/admin

You can not go past 9 levels.

alan d.’s picture

Note these were two different fatal testing errors triggered, one per test run:

First test: FormTest::testMultiFormSameNameErrorClass()
Second test: RenderTest::testDrupalRenderRenderCachePlaceholder()

Maybe re-test in a few days

lokapujya’s picture

Ok, this seems like a reasonable change to allow only one level. Should we have some automated tests?

Just want to point out that the Block Admin page only has one level and seems to work (allows only vertical dragging.) However, I think it uses it's own tabledrag functionality.

Seems like the use of MENU_MAX_DEPTH should be investigated (separately.)

lokapujya’s picture

.

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
ankitgarg’s picture

Rerolled.

lokapujya’s picture

Status: Needs review » Needs work
+++ b/core/misc/tabledrag.js
@@ -58,7 +58,7 @@ Drupal.tableDrag = function (table, tableSettings) {
-  this.maxDepth = 0; // Maximum amount of allowed parenting.
+  this.maxDepth = -1; // Maximum amount of allowed parenting. -1 if unlimited.

why is the change to the comment removed in the reroll?

adci_contributor’s picture

Update #19 in according to #20.
Please review.

Status: Needs review » Needs work

The last submitted patch, 21: tabledrag-decouple-depth-1310642-21.patch, failed testing.

nod_’s picture

Issue tags: +Needs reroll
googletorp’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new1.8 KB

Rerolled the patch from #21

nod_’s picture

Looks good to me. If someone could test that and it works as expected, feel free to RTBC I'm happy with the JS.

droplet’s picture

maartendeblock’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

No longer applies correctly, needs a reroll.

joshi.rohit100’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new1.56 KB

re-rolled.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

droplet’s picture

Status: Needs review » Needs work
Issue tags: +Needs JavaScript testing, +JavaScriptTest

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

sahil.goyal’s picture

StatusFileSize
new1.61 KB
new2.64 KB

I have rerolled the #29 patch as it is no longer getting compatible with the 9.4.x and also attaching the reroll_diff, making the issue to same state as it needs tests for JS as added in tags as well.

_utsavsharma’s picture

StatusFileSize
new2.35 KB
new2.74 KB

Fixed CCF for #42.
Please review.

_utsavsharma’s picture

Status: Needs work » Needs review

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

rishabh vishwakarma’s picture

Version: 9.5.x-dev » 10.1.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.49 KB
new3.38 KB

Adding reroll against 10.1.x

ranjith_kumar_k_u’s picture

StatusFileSize
new2.8 KB

Re-rolled #43 for 9.5

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new85 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

bhaveshithape’s picture

Status: Needs work » Needs review
StatusFileSize
new1.49 KB

Adding Rerole for d10, As previous patch failed to apply on d10.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

Removing credit for #50 as #47 still applies to 10.1, was duplicate patch. All patches should include an interdiff so that may have helped.

This still needs test coverage.

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.

pameeela’s picture

Looked at this for Bug Smash triage, but I can't work out how to reproduce the issue. If anyone is facing this on their current D10 site could you please update the issue summary with specific steps to reproduce?

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.