Review main Merged

94847[BUGFIX] Preserve option order of DB-stored forms on MySQL

Oli Bartsch CR +2 V +2 Hard +321 −3 updated 07/22/26, 08:50

Commit message

Multi-value form elements (SingleSelect, MultiSelect, RadioButton,
MultiCheckbox) persist their "options" as an associative map keyed
by option value. json_encode() of such a map produces a JSON
object, and MySQL's native JSON column type does not guarantee
that a JSON object's member order survives a write/read round
trip, unlike JSON array element order, which is preserved
reliably. As a result, reordering a select element's options in
the form editor appeared to save correctly, but reverted to the
previous order on the next reload.

This adds JsonObjectKeyOrderPreserver, which wraps order-sensitive
"options" maps in an array-based structure before persisting the
form definition to the database, and unwraps it again on read
using the explicit order list rather than relying on the object's
member order.

Review

  • Code review CR +2 Done
    • Oli Bartsch +2
    • Stefan Bürk +1
    • Josua Vogel +1
  • Verified V +2 Done
    • Oli Bartsch +2
    • Stefan Bürk +1
    • Josua Vogel +1
    • core-ci +1 CI

Issues 2

Files 5

Review log 1218

  1. Oli Bartsch uploaded patch set 1 07/20/26, 12:10

  2. core-ci voted on patch set 1 V -1 07/20/26, 12:17 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105027

  3. core-ci voted on patch set 1 V +1 07/20/26, 12:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105027

  4. Josua Vogel updated the commit message in patch set 2 V +1 07/20/26, 16:33

  5. core-ci voted on patch set 2 V +1 07/20/26, 16:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105037

  6. Stefan Bürk commented on patch set 2 07/21/26, 16:51

    JsonObjectKeyOrderPreserverTest.php:24

    UnitTestCase (TF) and not plain phpunit testcase.

    JsonObjectKeyOrderPreserverTest.php:31

    No need to have that as a property. Can be simply ctated in the test method(s).
  7. Stefan Bürk commented on patch set 2 07/21/26, 16:52

    Should that not be covered by a functional tests really writing into the database and restoring it to see if it changes or not ? (or is preserved) ?
  8. Oli Bartsch uploaded patch set 3 V +1 07/21/26, 20:19

  9. Oli Bartsch commented on patch set 3 07/21/26, 20:19

    Reply

    Done

    JsonObjectKeyOrderPreserverTest.php:24 Reply

    Done

    JsonObjectKeyOrderPreserverTest.php:31 Reply

    Done
  10. core-ci voted on patch set 3 V +1 07/21/26, 20:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105122

  11. core-ci commented on patch set 3 07/21/26, 21:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105129

  12. Stefan Bürk commented on patch set 3 07/22/26, 00:53

    JsonObjectKeyOrderPreserver.php:60

    ```suggestion final readonly class JsonObjectKeyOrderPreserver ```

    JsonObjectKeyOrderPreserver.php:64

    `protect()` is not idempotent. Running it twice would re-wrap the wrapper (the wrapper is itself a non-list map under key `options`… no — the wrapper is under the original `options` key; a second pass sees `options => {marker,order, values}` which is a non-list map and *would* wrap again). In the normal flow this cannot happen: the in-memory `FormData` is always the *restored* (clean) form, so persist always starts from unwrapped data. Latent fragility only if a future caller ever persists an already-protected array. Low risk; could be hardened with an early `if isset($value[self::MARKER]) continue;` guard, but not required.
  13. Stefan Bürk commented on patch set 4 V +1 07/22/26, 00:54

    Published edit on patch set 3.
  14. core-ci voted on patch set 4 V +1 07/22/26, 01:01 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105131

  15. Stefan Bürk commented on patch set 4 CR +1 V +1 07/22/26, 01:04

    Reply

    Thanks for adding one.

    JsonObjectKeyOrderPreserver.php:60 Reply

    Fix applied.

    DatabaseStorageAdapterFunctionalTest.php:135

    Verified locally that this functional test fails (red) without the fix, which confirms that the change really works and is the real regression check on db persisting layer (for this narrowed down issue). Thanks for adding it as requested.
  16. Josua Vogel voted on patch set 4 CR +1 V +1 07/22/26, 08:33

  17. Oli Bartsch voted on patch set 4 CR +2 V +2 07/22/26, 08:50

  18. Oli Bartsch merged patch set 5 07/22/26, 08:50