3rd-party should be able to alter the EntityListBuilder rows

Created on 29 June 2021, over 3 years ago
Updated 31 July 2024, 4 months ago

Problem/Motivation

There's no way for 3rd-party to alter the rows built by EntityListBuilder (and successors). Of course, swapping the list builder handler class is always on the table. But that solution has the known issue of condition race. Several module may swap that class but only one will win.

Use case

In πŸ“Œ Remove drupal_static() from node_mark() Fixed we want to move the node_mark() logic from Node to History module, where it belongs. The obvious approach would be to intercept the rows built by NodeListBuilder::buildRow(), in History module (which depends on Node), and add the node markers. This is not possible right now without swapping the Node list builder handler class. But that sucks...

Proposed resolution

Dispatch an event inside EntityListBuilder::render() just before the row is added to the table that allows to alter the row. Pass all meaningful context, such as the entity.

Remaining tasks

None.

User interface changes

None.

API changes

  • A new event EntityListBuilderRowEvent is dispatched just before the row is assembled in the table.

Data model changes

None.

Release notes snippet

In order to alter an entity list builder row, third-party code should listen to EntityListBuilderRowEvent::class event and use the event getters ans setters to manipulate the row,

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

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

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    this was previously tagged for a change record which still needs to happen
    MR should be updated for 10.1 and there was 1 open thread that should be addressed.

    Thanks.

  • πŸ‡­πŸ‡ΊHungary Sweetchuck Budapest

    What if I would like to add a new column?
    Then I should be able to add field into the ::buildHeader() as well. Not just in the ::buildRow()

    What if I would like to add something above or below the table?
    What if I would like to add new rows to the table? For example with colspan=42 which contains a long description which belong to the previous or next row.

    Then it would be useful to have a dispatched event in the ::render(), to be able to alter the whole $build render array.

    This issue can be a quick fix for the problem.

    Most of the time EntityListBuilder is used for config entities (in the original topic there is a use case for NodeListBuilder).

    What is the user story here?

    As a side builder I would like to be able make changes on pre-defined lists, such as "Node types", "Image Styles", "Block types", "User roles" and so on.

    • modify existing fields
    • remove existing fields
    • add new fields
    • alter filtering options
    • alter sorting options
    • change the layout of the listed items (table vs anything else)

    For me this sound like a task for "views".
    Unfortunately, event the config_views β†’ can't handle this task properly, because there is not enough support and metadata on config schema.

    This is also related: #2318187: FieldDefinitionInterfacegetDefaultValue() requires an entity β†’

    I think the whole EntityListBuilder concept should be replaced with a views based solution.

Production build 0.71.5 2024