TLDR

Add an option in Configurator_SequenceTabledrag to allow string keys instead of numeric keys.

Background / history

The Configurator_SequenceTabledrag allows to configure a sequence of components instances of the same type.
It allows to add, delete and reorder.
E.g. it can be used to build a sequence of EntityDisplay components.
All the items will have sequential numeric keys.

Problem

In some cases it will be useful to have custom string keys for items.

E.g. to configure a list of tabs that should be controlled by url hash, the url hash can be encoded in the string keys.

Spec / Desired behavior

In the "sequence" mode, the Configurator_SequenceTabledrag needs to behave exactly as before.
In the "assoc" mode, it should behave like this:

Stored config value:
Like before, but with string keys instead of numeric keys.

Returned value:
Like before, but with string keys instead of numeric keys.

Summary:
Use the string keys in the item labels.

Form:
Show a textfield for the string key next to the "Add item" button.
The string key is defined when adding a new item.
Show string keys in the form item labels.
Do NOT show a textfield for the string key in existing items, to avoid clutter in the form.
The only way to change a string key is to remove the item and insert a new item with the same config. The copy/paste functionality can help with that.

Implementation

Add the new mode to Configurator_SequenceTabledrag.
Add a static factory Configurator_SequenceTabledrag::createAssoc().

(I previously experimented with a shared base class and a separate class Configurator_AssocTabledrag, but it was really hard to separate the two.)

Risks

The class gets more complex.

The extended API needs to be supported in the future.

Comments

donquixote created an issue. See original summary.

donquixote’s picture

Title: Introduce Configurator_AssocTabledrag for sequences with string keys » Support string keys / associative arrays in Configurator_SequenceTabledrag
Issue summary: View changes
donquixote’s picture

Issue summary: View changes
donquixote’s picture

Component: Miscellaneous » Configurators

  • donquixote committed 6c33199 on 7.x-2.x
    Issue #3164104: Support a 'mixed' assoc mode in...
  • donquixote committed b4e9a6d on 7.x-2.x
    Issue #3164104: Support associative arrays in...
donquixote’s picture

Fixed in 7.x-2.0-alpha6.

donquixote’s picture

Status: Active » Fixed

  • donquixote committed 0641782 on 7.x-2.x
    Issue #3164104: (regression) Class const visibility can be used in PHP 7...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.