Motivation

The tabledrag functionality does not allow avoiding a child item to become a root item. This is very useful when there is a differentiation between the root level items, and the ones below. If we have, say, type A and type B, and the business logic implies all B items MUST be children of A items, there is currently no way to allow A items do be drag only among it's sibling A items and at the same time have B items only be draggable inside the A items.

Proposed resolution

Define an attribute to limit the min-depth of a row (and perhaps max-depth also?), making it never move to the side of it's parent leveling.

Remaining tasks

Perhaps adding the same functionality but for max-depth.

API changes

// Define a row's minimum depth.
$form['table'][$row->id()]['#attributes']['data-tabledrag-min-depth'] = 1;

Comments

lucas.constantino created an issue. See original summary.

lucas.constantino’s picture

StatusFileSize
new3.39 KB
lucas.constantino’s picture

Status: Needs work » Needs review

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.

kristen pol’s picture

Version: 8.9.x-dev » 9.1.x-dev
Status: Needs review » Needs work
Issue tags: -JavaScript +JavaScript, +Needs reroll

If this is still relevant, it needs a reroll for 9.1.x.

hardik_patel_12’s picture

Assigned: Unassigned » hardik_patel_12

Working on it

hardik_patel_12’s picture

Assigned: hardik_patel_12 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.48 KB

Re-rolling against 9.1.x.

hardik_patel_12’s picture

Issue tags: -Needs reroll
kristen pol’s picture

Status: Needs review » Needs work

Thanks for the reroll. I noticed a couple nitpicks:

+++ b/core/misc/tabledrag.js
@@ -882,7 +888,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
+    ¶
+    minIndent = Math.max(minIndent, this.minDepth);
+    maxIndent = Math.max(maxIndent, this.minDepth);
+    ¶

Extra spaces for two lines.

msuthars’s picture

Assigned: Unassigned » msuthars
msuthars’s picture

Assigned: msuthars » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.38 KB
new337 bytes

Updated the patch. Please review.

kristen pol’s picture

Thanks for the update. The changes address the items in #10. Tagging for manual and automated testing.

samiullah’s picture

Patch applied nicely

1 Created a menu item example books with multiple child elements and child elements having sub-child elements
2. Tried drag and drop among siblings of books element
3. Looks good

I would suggest one more round of manual testing for this one

droplet’s picture

Status: Needs review » Needs work
Issue tags: -Needs manual testing

not very sure if the Core needed it.

It's buggy if the start level is less than min-depth

Remove "Needs manual testing" since it has bugs and no tests

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.

varunmishra2006’s picture

StatusFileSize
new3.91 KB

Patch 3002325-12.patch is not compatible with version 9.5.3.
I have created an updated patch compatible with 9.5.3.

_utsavsharma’s picture

StatusFileSize
new2.75 KB
new3.99 KB

Tried to fix CCF for #21.

_utsavsharma’s picture

StatusFileSize
new2.1 KB
new2.1 KB

D10 patch.

nikhil_110’s picture

Status: Needs work » Needs review
smustgrave’s picture

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

Was previously tagged for tests which still need to happen.

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.