Problem/Motivation
Currently, Drupal's tabledrag.js (and Gin's override) does not support a minimum depth restriction. I have developed a custom first approach to solve this, which is currently working on my site by injecting a data attribute via a preprocess function and using a modified version of Gin's tabledrag.js.
Proposed resolution
I am currently using a preprocess to add the attribute: $form['terms'][$tid]['#attributes']['data-tabledrag-min-depth'] = 1; And I have updated tabledrag.js to honor this value.
The Long-term Vision: While this manual approach works for specific use cases, the goal is to implement a standardized way to configure this within the Taxonomy UI. This feature request proposes:
Vocabulary Configuration: Adding a "Minimum Depth" setting in the Taxonomy Vocabulary settings.
Dynamic Enforcement: Using the provided JavaScript logic to ensure that the drag-and-drop interface respects these boundaries automatically.
Remaining tasks
I have already adapted Gin's tabledrag.js to support the data-tabledrag-min-depth attribute (proposed in Core issue #3004458). This ensures:
Initialization: The row object captures the minDepth.
Swap Validation: isValidSwap prevents moving a row to a position where its depth would be less than the required minimum.
Indentation Control: The indent method locks the row at the minimum level even if the user tries to drag it to the root.
Keyboard Support: Arrow keys respect the minimum depth during reordering.
API changes
I am attaching the modified tabledrag.js (based on Gin's version) which includes these checks:
// Row constructor
const minDepthAttr = $tableRow.data('tabledrag-min-depth');
if (minDepthAttr !== undefined) {
this.minDepth = parseInt(minDepthAttr, 10);
}
// In isValidSwap
if (this.minDepth !== undefined && this.interval.max < this.minDepth) {
return false;
}
// In indent
if (this.minDepth !== undefined && indent < this.minDepth) {
indent = this.minDepth;
}Issue fork gin-3571298
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments