DraggableListBuilder's field requirements are confusing; don't require ['#markup']

Created on 30 June 2015, over 9 years ago
Updated 5 March 2025, 2 days ago

Problem/Motivation

When using DraggableListBuilder for a Config Entity listing page, you have to change the way you specify your rows from how EntityListBuilder works. To wit:

class MyEntityListBuilder extends EntityListBuilder {

  public function buildRow(EntityInterface $entity) {
    $row['label'] = $this->getLabel($entity);
    $row['id']= $entity->id();

    return $row + parent::buildRow($entity);
  }

  // ...
}

Compare to:

class MyEntityListBuilder extends DraggableListBuilder {

  public function buildRow(EntityInterface $entity) {
    $row['label'] = $this->getLabel($entity);
    $row['id']['#markup'] = $entity->id();

    return $row + parent::buildRow($entity);
  }

  // ...
}

Note the extra ['#markup'] that is required for all fields in the row, except for label. Without that, the listing form will not render correctly; which headers and columns are hidden get mixed up and the wrong ones hidden.

This makes DraggableListBuilder not a proper subclass of EntityListBuilder, as its API is different in silent, undocumented ways. (Fancy academic version: It's violating the Liskov Substitution Principle.)

Thanks to Tim Plunkett for helping locate this issue after I spent 90 minutes scratching my head about it. :-)

Proposed resolution

Whatever special treatment that label gets in order to make the #markup sub-property optional should be applied to all fields.

Remaining tasks

Do it.

API changes

I'd argue none. This is just a bug.

Data model changes

None.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component

entity system

Created by

🇺🇸United States Crell

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024