Problem/Motivation

From the 2.x roadmap in #3608015: [meta] Version 2.x: eliminate the complicated code for single child element default value handling.

When a multi-value element has exactly one child, valueCallback() accepts default values as plain literals, [0 => 'value 1'], instead of arrays keyed by the child element name. The shorthand saves callers a few characters but creates a problem: values coming back out of the form state always have the full structure, so anything that both reads and writes defaults has to handle two shapes. It also complicates every fix that touches the value pipeline, which is most of the open element-support issues.

Proposed resolution

Remove the shorthand. Default values are always keyed by delta and then by child element name, matching the submitted value structure exactly.

A non-array entry now throws \UnexpectedValueException naming the required structure, so code written for 1.x gets a clear message rather than an unhelpful TypeError further down the pipeline.

The MR also adds a phpstan.neon.dist to the module, since the value pipeline work benefits from static analysis being in place and the module already analyses clean at level 1.

Remaining tasks

Review.

User interface changes

None.

API changes

BC break for 2.0.0. Single-child elements passing literal default values must switch to the keyed structure:

// Before
'#default_value' => ['Foo', 'Bar'],

// After
'#default_value' => [['title' => 'Foo'], ['title' => 'Bar']],
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

darvanen created an issue. See original summary.

darvanen’s picture

Assigned: darvanen » Unassigned
Issue summary: View changes
Status: Active » Needs review
darvanen’s picture

Parent issue: » #3608015: [meta] Version 2.x