Problem/Motivation

Most of the open bugs in the queue share root causes in three parts of the element, and several of the stalled fixes conflict with each other because they patch the same two functions with different assumptions:

The 2.x meta (#3608015: [meta] Version 2.x) lists goals that all need these internals changed first. Rather than fix them piecemeal, this issue swaps the internals in one step, before any behavior changes.

Proposed resolution

Rework the internals with no behavior change. The existing test suite passes without a single change to a test file, which is the point: the tests define the element's contract and this issue proves the new internals honor it.

  • Element state becomes an ordered list of stable row IDs plus a next-ID counter, replacing items_count. Adding (and later removing) rows changes the list, never renumbers surviving rows.
  • The element gets its own theme hook, multivalue_form_element, with a preprocess adapted from core's FieldPreprocess. Markup and classes stay the same, so tabledrag and admin theme styling are unaffected. The preprocess already renders an _actions column, ready for the remove button.
  • Structural row keys (_weight, _actions) are declared in one constant and stripped from submitted values in one place.
  • The emptiness check moves to a dedicated isRowEmpty() method. Semantics are identical for now; it becomes the single override point when per-type empty detection lands.
  • The dependency on FieldStorageDefinitionInterface is dropped.
  • core_version_requirement becomes ^11.3 || ^12. The theme registration uses initial preprocess (11.3+), and a new major is the moment to drop Drupal 10.

Remaining tasks

Review and merge. Follow-ups are separate issues under #3608015: [meta] Version 2.x, in roughly this order:

  1. #3185539: Add a delete button
  2. #3199298: Don't add an empty element in some cases
  3. #3218021: Option for max cardinality
  4. #3232914: text_format elements are not supported
  5. #3252441: Invalid date when using datetime type inside multivalue
  6. #3280346: entity_autocomplete support
  7. #3482809: Saves unchecked checkboxes
  8. #3199172: Handle default values of nested elements
  9. Drop the single-child default value shorthand (no issue yet).

API changes

None for forms using the element. Sites overriding field-multiple-value-form.html.twig to affect this element should override multivalue-form-element.html.twig instead — which no longer drags core field widgets along with it.

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
Status: Active » Needs review

step 1 ready for review :)

darvanen’s picture

Sorry for the delay, ready for review.

sardara’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks!

  • sardara committed 970636b9 on 2.0.x authored by darvanen
    task: #3608087 2.x Internals Update
    
    By: darvanen
    By: sardara
    
sardara’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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