Review main Merged

90484[TASK] Drop stateful TCAdefaults in DataHandler

Daniel Windloff CR +2 V +2 Expert +677 −374 updated 10/23/26, 07:09

Commit message

DataHandler kept resolved TCAdefaults in the stateful property
$defaultValues, which was re-populated for every new record. Default
values are now resolved for each new record individually by the new
stateless DefaultValuesResolver, from page TSconfig of the record's
page, user TSconfig and TCA, without keeping any state in the
DataHandler instance.

Page TSconfig takes precedence over user TSconfig, type-specific
values over field-level values of the same source - the same order
FormEngine uses. Default values are now applied to all fields of a new
record, not only to the fields of its record type.

The content element restriction hook uses the same resolver for new
records, so omitted CType or colPos values cannot bypass restrictions.

The following internal property and methods have been removed:

- DataHandler->defaultValues
- DataHandler->setDefaultsFromUserTS()
- DataHandler->processTypeSpecificTcaDefaults()
- DataHandler->newFieldArray()
- DataHandler->getTypeSpecificDefault()

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Josua Vogel +1
    • Simon Schaufelberger +1
  • Verified V +2 Done
    • Benni Mack +2
    • Oliver Klee +1
    • Josua Vogel +1
    • Simon Schaufelberger +1
    • core-ci +1 CI

Issues 3

Files 12

Review log 5176

Show 3151 earlier messages
  1. Daniel Windloff uploaded patch set 1 08/25/25, 07:43

  2. core-ci voted on patch set 1 V -1 08/25/25, 07:50 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83842

  3. Benni Mack uploaded patch set 2 V -1 01/21/26, 15:53

  4. core-ci voted on patch set 2 V -1 01/21/26, 16:12 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/93963

  5. Benni Mack uploaded patch set 3 V -1 01/23/26, 21:29

  6. core-ci voted on patch set 3 V -1 01/23/26, 21:42 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/94213

  7. Garvin Hicking updated the commit message in patch set 4 V -1 01/23/26, 22:09

  8. core-ci voted on patch set 4 V -1 01/23/26, 22:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/94215

  9. Daniel Windloff commented on patch set 4 V -1 02/04/26, 15:50

    - Later added default values for each tca record type isn't respected. - Default handling for colpos
  10. Daniel Windloff commented on patch set 4 02/05/26, 09:02

    On it
  11. Daniel Windloff uploaded patch set 5 V -1 02/05/26, 11:28

  12. Daniel Windloff commented on patch set 5 V -1 02/05/26, 11:28

    Still on it
  13. core-ci voted on patch set 5 V -1 02/05/26, 12:05 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95137

  14. Daniel Windloff uploaded patch set 6 V -1 02/05/26, 12:24

  15. core-ci voted on patch set 6 V -1 02/05/26, 12:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95141

  16. Daniel Windloff uploaded patch set 7 V -1 02/05/26, 12:54

  17. core-ci voted on patch set 7 V -1 02/05/26, 13:05 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95143

  18. Daniel Windloff uploaded patch set 8 V -1 02/05/26, 13:37

  19. core-ci voted on patch set 8 V -1 02/05/26, 13:45 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95150

  20. core-ci voted on patch set 8 V +1 02/05/26, 13:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95150

  21. Daniel Windloff uploaded patch set 9 V +1 02/05/26, 14:24

  22. core-ci voted on patch set 9 V -1 02/05/26, 15:08 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95158

  23. Daniel Windloff uploaded patch set 10 V -1 02/05/26, 15:19

  24. core-ci voted on patch set 10 V -1 02/05/26, 15:29 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95171

  25. Daniel Windloff uploaded patch set 11 V -1 02/06/26, 07:17

  26. Daniel Windloff commented on patch set 11 02/06/26, 07:17

    Reply

    Done
  27. core-ci voted on patch set 11 V +1 02/06/26, 07:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95241

  28. Benni Mack voted on patch set 11 CR +1 V +1 02/12/26, 16:47

  29. Simon Schaufelberger commented on patch set 11 CR -1 02/12/26, 17:17

    Important-107327-DataHandlerDefaultValueRelatedPropertyAndMethodsRemoved.rst:24

    format not correct. Must be `:php:xxx` and I also see more spaces in other places after the "-". Please also add an empty line before the list.
  30. Simon Schaufelberger commented on patch set 11 02/12/26, 17:19

    DefaultValuesTest.php:237

    this is super hard to read. can we use empty lines after each assert?

    DefaultValuesTest.php:291

    remove empty line
  31. Daniel Windloff uploaded patch set 12 CR +1 V +1 02/13/26, 08:13

  32. Simon Schaufelberger commented on patch set 12 CR +1 02/13/26, 08:29

    Important-107327-DataHandlerDefaultValueRelatedPropertyAndMethodsRemoved.rst:24 Reply

    Done

    DefaultValuesTest.php:237 Reply

    Done

    DefaultValuesTest.php:291 Reply

    Done
  33. core-ci voted on patch set 12 V +1 02/13/26, 08:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95806

  34. Daniel Windloff rebased onto patch set 13 CR +1 V +1 04/21/26, 15:07

  35. core-ci voted on patch set 13 V +1 04/21/26, 15:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100661

  36. Benni Mack updated the commit message in patch set 14 V +1 04/22/26, 07:21

  37. Benni Mack commented on patch set 15 06/30/26, 21:57

    Published edit on patch set 14.
  38. core-ci voted on patch set 15 V -1 06/30/26, 22:05 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/104093

  39. Daniel Windloff uploaded patch set 16 V -1 07/12/26, 07:39

  40. Daniel Windloff uploaded patch set 17 07/12/26, 07:44

  41. core-ci voted on patch set 16 V -1 07/12/26, 07:47 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/104680

  42. core-ci voted on patch set 17 V +1 07/12/26, 07:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/104681

  43. Simon Schaufelberger voted on patch set 17 CR +1 07/13/26, 10:38

  44. Daniel Windloff rebased onto patch set 18 CR +1 V +1 07/30/26, 08:14

  45. core-ci voted on patch set 18 V +1 07/30/26, 08:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105671

  46. Daniel Windloff uploaded patch set 19 V +1 08/15/26, 05:34

  47. core-ci voted on patch set 19 V +1 08/15/26, 05:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/106751

  48. Stefan Bürk commented on patch set 19 08/15/26, 06:32

    DataHandlerContentElementRestrictionHook.php:100

    That's pretty use-less now - the result is the $incomingFieldArray every time. Not applying default values here anymore - not verified if that's correct here - makes the complete `else {}` branch obsolete and can be simply dropped. Furter it would allow to negate the first if condition in the loop and do a early return and unnest the block one-level and making that part a little slimmer.
  49. Daniel Windloff commented on patch set 19 08/15/26, 07:34

    DataHandlerContentElementRestrictionHook.php:100 Reply

    As far as I remember, the situation is: The default values never applied properly for new records during this check. Only default values from UserTS have been evaluated before this hook has been initiated before my change, leaving the majority of sources of default values unattended. As I think this was and is a bug, I marked it with a todo as it should be resolved later.
  50. Daniel Windloff uploaded patch set 20 V +1 09/04/26, 06:32

  51. core-ci voted on patch set 20 V -1 09/04/26, 06:44 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/107802

  1. Daniel Windloff uploaded patch set 21 V -1 09/04/26, 06:47

  2. core-ci voted on patch set 21 V +1 09/04/26, 07:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/107810

  3. Stefan Bürk commented on patch set 19 09/15/26, 08:30

    DataHandlerContentElementRestrictionHook.php:100 Reply

    I checked this again and more closely now. This is more than dead code, previous to this change `DataHandler::start()` filled in the `$defaultValues` from UserTsConfig **before** `process_datamap()` calls the `processDatamap_beforStart` hooks. That means, that these hooks see a UserTsConfig `TCAdefaults.tt_content.CType`/`colPos`, which is no longer the case with this change. I suggest that we should resolve `CType` and `colPos` here in the same order `DataHandler` uses: incoming value, then PageTsConfig of the target page, then the UserTsConfig and than the TCA defaults) instead of keeping the `@todo`. That would closes both cases and makes `array_merge([], ...)` vanish here. This should also be covered with a functional test.

    DataHandler.php:524

    The order listed here differs from the old one. Before, a type-specific value from *any* source beat any field-level value (user TS `types.1` won over page TS field-level). Now page TS field-level wins. That matches FormEngine (`DatabaseRowInitializeNew`) and `Feature-107281`, so I think it is correct. But it is a behaviour change for integrators. Could you mention it in the commit message? `defaultValueFallback` fails on the parent commit on exactly that step.

    DataHandler.php:526

    The leak described in #107327, where page TSconfig `TCAdefaults` of one record are merged into `$this->defaultValues` and then applied to all records processed afterwards, is not new. It exists since #89211 (2020) and I could reproduce it on 12.4, 13.4, 14.3 and main. Because this patch removes `@internal` API, it can not be backported to fix that. So I extracted the plain bugfix into its own issue and change, without any API change: * Forge: https://forge.typo3.org/issues/110705 * Gerrit: https://review.typo3.org/c/Packages/TYPO3.CMS/+/95839 (main), with backports 95840 (14.3) and 95841 (13.4) Could you rebase this change onto 95839 once it is merged, so the refactoring sits on top of the fix rather than being the fix? The conflict is limited to `applyDefaultsForFieldArray()`, which this patch rewrites anyway, and to `DefaultValuesTest`.

    DataHandler.php:546

    The type falls back to the TCA default of the type field, but a `TCAdefaults.<table>.<typeField>` from page/user TS is ignored. With `TCAdefaults.pages.doktype = 254` and `description.types.1 = standard` / `description.types.254 = folder`, the page is created as a folder but gets `description = standard`, together with the `columnsOverrides` defaults of type 1. This was already the case before (through the early `newFieldArray()`), so it does not block. But taking the type from the first source that defines an existing type, in the same order as the values ``` incoming -> page TS -> user TS -> TCA ``` is only a few lines and keeps type and values consistent. It also removes the duplicated `$schema->getField($schema->getSubSchemaTypeInformation()->getFieldName())`.

    DataHandler.php:551

    This drops global PageTSConfig (`EXT:*/Configuration/page.tsconfig`) for everything created on `pid 0`. Before, `getPagesTsconfig(0)` was used instead and FormEngine applied it for pid 0 too. My assumption here is, that this guard has been added here for unit tests failing with `NoSuchCacheException: runtime` - or am I wrong here ? What about passing the resolved TCAdefaults into the method instead, for example: ``` $this->applyDefaultsForFieldArray( $table, BackendUtility::getPagesTSconfig($tscPID)['TCAdefaults.] ?? [], $fieldArray, $incomingFieldArray, ); ``` What do you think ?

    DataHandler.php:576

    Small nit-pick, the comments sit at the end of the *previous* branch, and every condition repeats `$schema->getName() . '.'` / `$field->getName()` / `$subschema->getField(...)`. The sub-schema line is about 300 characters). Locals such as `$pageTsDefaults = $pageTsConfig['TCAdefaults.'][$table . '.'] ?? []`, `$fieldName` and `$subSchemaField` make the chain readable without the comments. `$schema->getName()` is `$table` anyway.

    Important-107327-DataHandlerDefaultValueRelatedPropertyAndMethodsRemoved.rst:18

    `:php\`DataHandler->defaultValues\`` — missing colon after `php`, the role does not render.

    Important-107327-DataHandlerDefaultValueRelatedPropertyAndMethodsRemoved.rst:20

    `applyDefaultsForFieldArray` is protected, so there is no need to point readers to it. "Moved to `process_datamap()`" does not say much either. Maybe describe what changed instead: defaults are now resolved per new record, without keeping state in the DataHandler instance. Also mention that the removed members were `@internal`. The leak between records is fixed separately (#110705 / 95839), so this changelog only needs to cover the removed internals.

    DefaultValuesTest.php:167

    95839 adds a test for the same scenario `defaultValuesFromPageTSconfigAreNotAppliedToRecordsOnOtherPages`, content elements on two sibling pages in one DataHandler run. After rebasing onto it, this test can either be dropped or kept as the `pages` variant, including the sub-page case.

    DefaultValuesTest.php:176

    Small nit-pick: empty line inside the array.

    DefaultValuesTest.php:192

    `$this->get(DataHandler::class)` rather than `GeneralUtility::makeInstance()` in new functional tests.

    DefaultValuesTest.php:210

    Seven scenarios in one test. A data provider (or one test per source) would name the failing step. The test name does not say what is expected either. Typos in the comments: `UsrTSConfig`, `UseTSConfig`, `specifc`.

    DefaultValuesTest.php:272

    `@todo` (lowercase) is the core convention. Flushing only the runtime cache (`$this->get('cache.runtime')->flush()`) is enough: `getPagesTSconfig()` caches per pid there, and `modifyRecord()` does not invalidate it.

    be_users_admin.csv:10

    This fixture is shared by 31 test files. Could the scenario users go into a DataSet next to `DefaultValuesTest` instead? User 3 also reuses the username `foo`, and there is a trailing blank line.
  4. Stefan Bürk commented on patch set 21 CR -1 13 comments 09/15/26, 08:30

    Thanks for sticking with this, the stateless per-record resolution is the right direction. I found two regressions and wrote tests for them: 1. The content element restriction hook no longer sees user TS `CType`/`colPos` defaults, so a disallowed CType can be stored. It was rejected previously. 2. Records on pid 0 no longer get global page TSconfig `TCAdefaults` because of the `$pageId !== 0` guard. Details and a suggested approach are in the inline comments. I have the functional tests and a small patch ready if you want them. Minor: changelog RST role, fixture, test naming, commit subject. About the leak itself: it exists since 2020 on every branch, and this patch can not be backported because it removes API. So I extracted a minimal bugfix without API changes: forge #110705, change https://review.typo3.org/c/Packages/TYPO3.CMS/+/95839 for main, with the backports 95840 (14.3) and 95841 (13.4). Please rebase this change onto it later, once it is merged, and treat this one as the refactoring on top of it.
  5. Stefan Bürk commented on patch set 21 09/15/26, 08:52

    On it .. stay tuned ..
  6. Stefan Bürk uploaded patch set 22 CR -1 V +1 09/15/26, 09:05

  7. core-ci voted on patch set 22 V +1 09/15/26, 09:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108599

  8. Stefan Bürk commented on patch set 21 09/15/26, 09:29

    DataHandler.php:524 Reply

    Done in patch set 22: the precedence change is mentioned in the commit message and in the changelog.

    DataHandler.php:526 Reply

    The isolated fix is https://review.typo3.org/c/Packages/TYPO3.CMS/+/95839 (forge #110705, backports 95840 and 95841). Patch set 22 is rebased on top of it, so this change is the refactoring only now.

    DataHandler.php:546 Reply

    Done in patch set 22. The record type is taken from the first source defining an existing type: incoming data, page TSconfig, user TSconfig, TCA default. A type pointing to a field of a related record (like uid_local:type) is not resolved from the local value anymore. Covered by DefaultValuesResolverTest and typeSpecificDefaultsUseRecordTypeDefinedByTsConfigDefault.

    DataHandler.php:551 Reply

    Confirmed: without the guard the unit tests failed with "NoSuchCacheException: runtime". Done in patch set 22: the caller passes BackendUtility::getPagesTSconfig($tscPID)['TCAdefaults.'] into applyDefaultsForFieldArray(), the guard is gone, and defaultValuesFromGlobalPageTsConfigAreAppliedForRecordsOnRootLevel covers records on pid 0.

    DataHandler.php:576 Reply

    Done in patch set 22. The resolution moved into DefaultValuesResolver, using $pageTsDefaults, $userTsDefaults, $fieldName and $subSchemaField locals, without the misplaced comments.

    Important-107327-DataHandlerDefaultValueRelatedPropertyAndMethodsRemoved.rst:18 Reply

    Fixed in patch set 22.

    Important-107327-DataHandlerDefaultValueRelatedPropertyAndMethodsRemoved.rst:20 Reply

    Done in patch set 22. The description covers the stateless resolution per record, the behaviour changes and the removed internal members, and no longer points to protected methods.

    DefaultValuesTest.php:167 Reply

    Kept as the pages variant including the sub page case, renamed to defaultValuesFromPageTSconfigAreAppliedToSubPagesOnly, next to the test from 95839.

    DefaultValuesTest.php:176 Reply

    Fixed in patch set 22.

    DefaultValuesTest.php:192 Reply

    Done in patch set 22.

    DefaultValuesTest.php:210 Reply

    Done in patch set 22: replaced by defaultValuesAreTakenFromSourceWithHighestPrecedence, with one named data provider case per source. The typos are gone with it.

    DefaultValuesTest.php:272 Reply

    Done in patch set 22. It turned out the flush is not needed at all, the tests pass without it, so the flush and the @TODO are both removed.

    be_users_admin.csv:10 Reply

    Done in patch set 22. The shared fixture is untouched, the scenario users live in DataSet/BackendUsersWithTcaDefaults.csv with unique user names.
  9. Stefan Bürk commented on patch set 19 09/15/26, 09:29

    DataHandlerContentElementRestrictionHook.php:100 Reply

    Done in patch set 22. For new records the hook now resolves the default values with the new DefaultValuesResolver, the same service DataHandler uses: incoming value, page TSconfig of the target page, user TSconfig, then TCA, including type-specific values. So leaving out CType or colPos no longer bypasses the restriction. The @todo lines and the array_merge([], ...) are gone, and DataHandlerContentElementRestrictionHookTest covers allowed and rejected cases.
  10. Stefan Bürk uploaded patch set 23 V +1 09/15/26, 10:34

  11. core-ci voted on patch set 23 V +1 09/15/26, 10:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108612

  12. Benni Mack wrote 10/16/26, 07:45

    Topic set to DataHandler
  13. Daniel Windloff uploaded patch set 24 V +1 10/16/26, 11:44

  14. core-ci voted on patch set 24 V +1 10/16/26, 11:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111353

  15. Daniel Windloff marked it ready for review 10/16/26, 11:54

  16. Oliver Klee voted on patch set 24 V +1 10/17/26, 17:10

  17. Benni Mack commented on patch set 24 10/22/26, 15:52

    Reply

    Done
  18. Daniel Windloff rebased onto patch set 25 V +1 10/22/26, 15:52

  19. core-ci voted on patch set 25 V +1 10/22/26, 16:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112141

  20. Oliver Klee voted on patch set 25 V +1 10/22/26, 17:45

  21. Josua Vogel voted on patch set 25 CR +1 10/22/26, 19:30

  22. Josua Vogel voted on patch set 25 V +1 10/22/26, 19:44

  23. Simon Schaufelberger voted on patch set 25 CR +1 V +1 10/22/26, 20:58

  24. Benni Mack voted on patch set 25 CR +2 V +2 10/23/26, 07:09

  25. Benni Mack merged patch set 26 10/23/26, 07:09