DraggableListBuilder / DraggableListBuilderTrait is brittle with its table cells

Created on 6 March 2024, over 1 year ago

Problem/Motivation

If an entity list builder using DraggableListBuilder / DraggableListBuilderTrait doesn't add anything to its rows, or adds them in the wrong order, the whole thing breaks and the drag handles don't show.

Steps to reproduce

1. Ensure there are at least 2 vocabularies
2. Comment out \Drupal\taxonomy\VocabularyListBuilder::buildRow()
3. Go to admin/structure/taxonomy

There are no drag handles!

Further investigation: in Drupal\Core\Entity\DraggableListBuilderTrait::buildRow() add a cell after the weight:

      $row['cell'] = [
        '#markup' => 'A CELL',
      ];

Reload and the table is still broken.

Now move the cell so it comes BEFORE the weight cell, and it works!

It seems that whatever is adding the drag handles is very particular about what it needs, and needs a cell that is NOT the entity operations to come first (but what's wrong with the operations that it doesn't like??)

This should:

a. Be documented on the trait
b. There should be some sort of warning to tell developers what they've done wrong

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated about 1 month ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @joachim
  • πŸ‡ΊπŸ‡ΈUnited States EHLOVader

    I ran into an issue with this while trying to implement DraggableListBuilderTrait on a custom entity ListBuilder.
    I was trying to get away without an entity draggable class to extend but getting the order of the columns is important.

    The draggable list anchor is added to the first cell in the rows. When I first attempted the implementation I had Weight before the table rows and since weight is hidden by default so was the anchor handle.

    I sorted this out after looking at the source from 2990784 ✨ Add a draggable list builder for content entities RTBC where I decided just to implement my own DraggableListBuilder based on it.

    That makes the order of buildRow calls [my buildRow]+[parent[ trait+parent] ] so I get my columns, weight column, operations column.

    but what's wrong with the operations that it doesn't like??

    I also think I know what the issue with this might be... with the operations being interactive it probably interferes with the click and drag actions of the anchor.

    I wonder if Draggable should have an anchor column, but not sure how it could reach out of the parent class to provide that at the beginning because of my experience with the order that each method runs.

Production build 0.71.5 2024