Action "List: add item" ignores specified key when setting a numeric key

Created on 25 April 2025, 21 days ago

Problem/Motivation

The action "List: add item" allows to create custom lists and provides an option "Set by specified key".
Such a custom list is mostly then a DataTransferObject created on runtime by ECA.

When setting a numeric key, then the DataTransferObject will apply a rekey:
https://git.drupalcode.org/project/eca/-/blob/2.1.x/src/Plugin/DataType/...

That leads to the problem that a specified numeric key will be dropped and replaced by a numeric sequence order of the list. So whenever the (numeric) key is important, for example when setting an options list in a form, then this mechanism to use a custom list for that case becomes unusable.

It may even be worse when not knowing about this fact, that wrong keys are being used within a process.

Steps to reproduce

Proposed resolution

Somehow we need to prevent the rekey logic when setting a specified key.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇩🇪Germany mxh Offenburg

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

Comments & Activities

  • Issue created by @mxh
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This is a challenging one. Should we probably introduce a flag in \Drupal\eca\Plugin\DataType\DataTransferObject to optionally turn off rekeying which should be called right before calling $list->set($index, $item); in the action plugin?

  • 🇩🇪Germany mxh Offenburg

    Should we probably introduce a flag in \Drupal\eca\Plugin\DataType\DataTransferObject to optionally turn off rekeying which should be called right before calling $list->set($index, $item); in the action plugin?

    Either this, or initialize a DTO with a rekey option, or do both. Maybe then let the user decide whether rekey should happen, by adding a corresponding option to the "List: add item" action? There is another place where someone can add an item to a list, for example with "Token: set value" using token name [mylist:+]. But I think that one is probably never used by anyone. Still there may be other places where an item is being added to a list (other actions, such as merging).

Production build 0.71.5 2024