Review main Ready for review Stale

95260[FEATURE] Introduce event to extend page tree query fields

Konrad Michalik CR 0 V 0 Normal +210 −1 updated 09/20/26, 05:54

Commit message

The new PSR-14 event BeforePageTreeIsQueriedEvent allows
extensions to add fields of the pages table to the page tree
query. The fields are then available in the _page record of
each tree item, e.g. in listeners of the existing
AfterPageTreeItemsPreparedEvent.

This avoids one query per tree item or XCLASSing the
TreeController when tree items should be enriched based on
custom pages fields.

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 6
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/60/95260/6 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/60/95260/6 && git cherry-pick FETCH_HEAD

Review

  • Code review CR 0 Needs a vote
  • Verified V 0 Needs a vote
    • core-ci +1 CI

Relation chain 2

  1. main 95134[BUGFIX] Allow PHP enums as `<f:form.select>` options Based on this change Christian Spoo CR 0 V 0 → 14.3 Normal +106 −3

    The chain has patch set 8 of 11, the changes above it need a rebase.

  2. 95260 [FEATURE] Introduce event to extend page tree query fields This change

Merge conflicts 2

Issues 1

Files 5

Review log 1420

  1. Konrad Michalik uploaded patch set 1 08/11/26, 08:05

  2. core-ci voted on patch set 1 V +1 08/11/26, 08:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/106408

  3. Garvin Hicking voted on patch set 1 CR +1 V +1 08/11/26, 09:26

  4. Oli Bartsch commented on patch set 1 08/11/26, 15:49

    BeforePageTreeIsQueriedEvent.php:41

    can we do an array_unique here? or maybe even already check on setting new fields?
  5. Konrad Michalik uploaded patch set 2 CR +1 V +1 08/12/26, 06:17

  6. core-ci voted on patch set 2 V +1 08/12/26, 06:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/106491

  7. Garvin Hicking voted on patch set 2 CR +1 V +1 08/12/26, 06:37

  8. Benni Mack commented on patch set 2 CR -1 08/12/26, 06:45

    I suggest we first free the constructor of the Repository, and then handle the field list better.
  9. Konrad Michalik commented on patch set 2 08/12/26, 07:42

    Reply

    Agreed, and that's the root cause rather than a detail. `$fields`, `$quotedFields`, `$currentWorkspace` and `$additionalQueryRestrictions` are all `readonly` and assigned in the constructor, so the field list is frozen before any extension point can run. This change works around that instead of fixing it, and I'm not attached to the current shape: if a freed constructor makes a different extension point more natural, I'm happy to rework this or drop the event entirely. For sizing: the class is marked `@internal this class is not public API yet`, so the constructor signature can change without a breaking changelog, and 5 of the 6 instantiation sites already call `makeInstance(PageTreeRepository::class)` with no arguments, `TreeController` is the only caller passing any. Is the refactoring something the team already has planned, or is it up for grabs? In the first case I'll wait and rebase on top; in the second I can prepare it as a separate task change. Either way, should I park this change as WIP in the meantime?

    BeforePageTreeIsQueriedEvent.php:41 Reply

    Done, I went with the check in `addField()` rather than `array_unique()` in the getter. `array_unique()` preserves keys, so with a duplicate in the middle the getter would return a list with a gap (`array_unique(["slug","abstract","slug","author"])` gives `[0 => 'slug', 1 => 'abstract', 3 => 'author']`) and would no longer match its `string[]` annotation, that would need an extra `array_values()` around it. Guarding on write keeps the array a proper list at all times. Added a unit test for it. One limitation worth mentioning: `PageTreeRepository::__construct()` does `array_merge($defaults, $additionalFieldsToQuery)` without deduplication, so a listener calling e.g. `addField('title')` still produces a duplicate column in the SELECT, the event cannot see collisions with the 32 default fields. It is harmless in SQL, but if you want uniqueness guaranteed end to end, `array_unique()` there would be the right place. Happy to include that in this change if you prefer, I left it out to keep the scope tight.
  10. Radostin Milenov uploaded patch set 3 CR +1 V +1 09/13/26, 06:59

  11. core-ci voted on patch set 3 V +1 09/13/26, 07:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108442

  12. Konrad Michalik commented on patch set 3 09/17/26, 15:01

    Hi Radostin, thanks for rebasing this onto current main. I noticed patch set 3 also drops two things from patch set 2 that were added based on review feedback: the in_array duplicate-check in BeforePageTreeIsQueriedEvent::addField(), and the fieldsAreAddedOnlyOnce() unit test covering it. Was that intentional, or did it get lost during a rebase/cherry-pick? Happy to restore both in a follow-up patch set if it was not deliberate.
  13. Radostin Milenov commented on patch set 3 09/17/26, 15:32

    That wasn’t intended. Will take care of it.
  14. Radostin Milenov rebased onto patch set 4 V +1 09/20/26, 04:30

  15. core-ci voted on patch set 4 V +1 09/20/26, 04:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108874

  16. Radostin Milenov uploaded patch set 5 V +1 09/20/26, 04:41

  17. Radostin Milenov commented on patch set 5 09/20/26, 04:43

    Reply Unresolved

    Done
    Sorry about that appaently i somehow broke my envrionment had to set it up fresh.

    BeforePageTreeIsQueriedEvent.php:41 Reply

    Done
  18. core-ci voted on patch set 5 V -1 09/20/26, 04:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108876

  19. Radostin Milenov commented on patch set 6 V -1 09/20/26, 05:46

    Published edit on patch set 5.
  20. core-ci voted on patch set 6 V +1 09/20/26, 05:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108880