Review main Work in progress Breaking

90502[!!!][TASK] Refactor link-viewhelpers and fix inconsistencies

Markus Klein CR -1 V 0 Expert +661 −675 updated 11/11/26, 15:18

Commit message

The processing of viewhelper arguments of link-related
viewhelpers (VHs) has been repeated in each of the VHs.
This led to quite some differences on how certain arguments
were treated. Specifically the 'pageType' argument did not
allow to reset the current one to zero.
This was either caused by wrong argument registrations or
improper and inconsistent handling afterward.

The typolink-logic always had support to reset the current pageType,
whereas Extbase's UriBuilder totally failed to implement this correctly.

This patch adds the UriBuilder handling for pageType
with value `null`, which allows for `0` to be a usable page type.

Moreover, all code within the VHs is extracted into traits
to get rid of all the code duplication.
There is now a single place for each argument and its processing
ensuring consistency for all related VHs.

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 21
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/02/90502/21 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/02/90502/21 && git cherry-pick FETCH_HEAD

Review

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

Merge conflicts 2

Issues 1

Files 15

Review log 3556

Show 1631 earlier messages
  1. Markus Klein uploaded patch set 1 08/28/25, 21:53

  2. Markus Klein uploaded patch set 2 08/28/25, 21:58

  3. Markus Klein commented on patch set 2 08/28/25, 21:58

    This change is ready for review.
  4. core-ci voted on patch set 1 V -1 08/28/25, 22:05 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83945

  5. core-ci voted on patch set 2 V -1 08/28/25, 22:09 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83946

  6. Markus Klein uploaded patch set 3 V -1 08/29/25, 06:15

  7. core-ci voted on patch set 3 V -1 08/29/25, 06:25 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83966

  8. Markus Klein uploaded patch set 4 V -1 08/29/25, 13:46

  9. core-ci voted on patch set 4 V -1 08/29/25, 14:03 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/83990

  10. Markus Klein rebased onto patch set 5 V -1 10/22/25, 14:34

  11. core-ci voted on patch set 5 V -1 10/22/25, 14:46 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/87272

  12. Markus Klein uploaded patch set 6 V -1 10/22/25, 15:36

  13. core-ci voted on patch set 6 V -1 10/22/25, 15:50 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/87276

  14. Markus Klein uploaded patch set 7 V -1 11/13/25, 23:56

  15. core-ci voted on patch set 7 V -1 11/14/25, 00:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/89609

  16. Markus Klein uploaded patch set 8 V -1 11/17/25, 01:22

  17. core-ci voted on patch set 8 V -1 11/17/25, 01:33 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/89891

  18. Markus Klein uploaded patch set 9 V -1 11/17/25, 23:53

  19. core-ci voted on patch set 9 V -1 11/18/25, 00:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/89977

  20. Markus Klein uploaded patch set 10 V -1 11/18/25, 09:02

  21. core-ci voted on patch set 10 V -1 11/18/25, 09:19 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90002

  22. Markus Klein uploaded patch set 11 V -1 11/18/25, 09:24

  23. core-ci voted on patch set 11 V -1 11/18/25, 09:33 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90003

  24. Markus Klein uploaded patch set 12 V -1 11/18/25, 10:15

  25. core-ci voted on patch set 12 V -1 11/18/25, 10:23 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90007

  26. Markus Klein uploaded patch set 13 V -1 11/18/25, 14:48

  27. core-ci voted on patch set 13 V -1 11/18/25, 14:56 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90042

  28. Markus Klein uploaded patch set 14 V -1 11/18/25, 16:08

  29. core-ci voted on patch set 14 V -1 11/18/25, 16:19 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90054

  30. Markus Klein uploaded patch set 15 V -1 11/18/25, 16:27

  31. core-ci voted on patch set 15 V -1 11/18/25, 16:36 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90057

  1. Markus Klein uploaded patch set 16 V -1 11/18/25, 16:39

  2. core-ci voted on patch set 16 V +1 11/18/25, 16:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90059

  3. Markus Klein uploaded patch set 17 V +1 11/20/25, 16:24

  4. core-ci voted on patch set 17 V +1 11/20/25, 16:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90316

  5. Markus Klein uploaded patch set 18 V +1 11/20/25, 16:45

  6. Markus Klein updated the commit message in patch set 19 11/20/25, 16:46

  7. Simon Schaufelberger voted on patch set 19 CR +1 11/20/25, 16:51

  8. core-ci voted on patch set 18 V +1 11/20/25, 16:55 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90320

  9. core-ci voted on patch set 19 V +1 11/20/25, 16:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/90321

  10. Oliver Hader voted on patch set 19 CR +1 11/22/25, 21:23

  11. Oliver Hader commented on patch set 19 11/22/25, 21:35

    Breaking-107347-ExtbasePhpUriBuildertargetPageTypeResetSupportAndFactionViewelperAdjusted.rst:41 Unresolved

    `UriBuilder::getTargetPageType()` is marked `@internal` at least since TYPO3 v10. Thus, I'm not sure if the overall impact of this change would be considered as "breaking" then.
  12. Stefan Bürk commented on patch set 19 11/23/25, 15:25

    Unresolved

    I must say, I'm not really a fan to extract this to "traits". Traits has no real connection. This could be considered `personal taste`, but I have hard times with the looseness of traits hiding things away and being to open/not-restricted. Special moving the "argument" registration to a trait and other things are "relying" on exactly them, which is "not" guarenteed directly. Classes using the traits "can still" override the methods and introduce changes in behaviour, mixing them. And in case of FormViewHelper these arguemnt method are not used from the trait at all and making the statement of this change inconsistent. I get the point and background extracting this to kind of shared places, just not sure if trait's are really the way to go. TBH not sure about a good alternative now, despite kind of "services" to use. If extracting to "traits" get's support, we should at least do following throughout the change (stating it here in a central place): * each trait must be marked as `@internal` to not make them "public api" and encourage usage outside of the core / TYPO3 system extension ViewHelpers and allowing changes (breaking) in patchlevel. * trait & method in trait needs to get docblock describing the useage/use-case of them * Method signature of methods in traits are not ensured ... usualy this is/should be done with a interface and a "trait" with default implementations, but there is no "native" way to bound them together. Not saying this is needed, only wanted to through that in. * Trait methods "expect" that the "corresponding argument register methods" has been executed/applied, but that is not guaranteed. Not sure how we should deal with this. I guess we need at least add method doc block stating "which" argument registrer method of the trait is required/dependency for the corresponding method - or similar.

    FormViewHelper.php:99 Unresolved

    The whole change is about "centralizeing" and avoid duplication. And "arguments" are extracted to used LinkViewHelperTrait methods not used here. So here arguments are still registerd on their own. For example `LinkViewHelperTrait->initializeCommonPageViewHelperArguments()`. Does this not make the change missing it's goal ? At least it is not consistant in what it states.

    LinkRenderTrait.php:26 Unresolved

    Can we somehow avoid "shorten" argument names ... and I guess we should add phpdocblock describing what kind of arguments each "closure" recieves when called. * $extbaseFunc($request, $this->arguments); * $feFunc($request, $this->arguments, $childContent); * $beFunc($request, $childContent); Who should someone from outside now what to expect or implement. Let's be a good example and document this at least. See "generic/global" comment about trait/method documentation in general.

    LinkViewHelperTrait.php:49 Unresolved

    ```suggestion $this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination. Value 0 means "current page"'); $this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter', false, 0); ``` This need to be changed to keep the current behavior. Due to the refactoring this has been flipped between these both, what was optional with/without a default is now required and what was required is now optional with a default of 0. If this is really intented, this need explanation in commit message and rest file. See: * https://review.typo3.org/c/Packages/TYPO3.CMS/+/90502/19/typo3/sysext/fluid/Classes/ViewHelpers/Uri/PageViewHelper.php#b49 * https://review.typo3.org/c/Packages/TYPO3.CMS/+/90502/19/typo3/sysext/fluid/Classes/ViewHelpers/Uri/PageViewHelper.php#b51 * https://review.typo3.org/c/Packages/TYPO3.CMS/+/90502/19/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ActionViewHelper.php#b51 * https://review.typo3.org/c/Packages/TYPO3.CMS/+/90502/19/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ActionViewHelper.php#b52 * https://review.typo3.org/c/Packages/TYPO3.CMS/+/90502/19/typo3/sysext/fluid/Classes/ViewHelpers/Link/ActionViewHelper.php#b50 * https://review.typo3.org/c/Packages/TYPO3.CMS/+/90502/19/typo3/sysext/fluid/Classes/ViewHelpers/Link/ActionViewHelper.php#b51 * ...
  13. Oliver Klee commented on patch set 19 11/23/25, 16:05

    For the traits, we can add `@phpstan-require-implements` to enforce that they only are used in classes that implement some interface: https://phpstan.org/writing-php-code/phpdocs-basics#enforcing-implementing-an-interface-for-traits
  14. Christian Kuhn commented on patch set 19 CR -1 11/23/25, 16:21

    UrlRenderTrait.php:32 Unresolved

    I'm not a great fan of traits when their sole use is DRY to then access state and/or methods from the implementation. Traits that cant't hurt us later must not access knowledge from the consuming class, but should at least get everything hand over. That's the only way to make them simple and helpful. As such, I suggest reviewing this patch to see how it looks if the traits don't access state from consuming classes. Also note that traits imho should not have properties usually, which means they can't use DI. In the end, if we go with these changes, they'll hardcode makeInstance() forever, or they need service dependencies hand over, which i'd prefer. This trait is a great example: It works only in a very small use case for classes in the same domain (these traits don't even resolve a cross cutting concern, which would be one of its few advantages) and its only purpose is to remove some lines of code. When the 4 affected VH's don't behave similar, they could and maybe should be aligned manually. After all, the VH's solve different things and just happen to share similar code, but for different purposes and with different configuration. DRY is often misunderstood as "same lines of code at different places is bad", but that's not the case: DRY is about not repeating knowledge, not lines of code. Glue code is no knowledge, and most of the stuff in here is glue code. All in all, I'm not a fan of this abstraction code. I think we should align the VH's a bit better if they behave too differently, maybe even merge some altogether, and see if the uri building abstraction could be streamlined a bit to need less setup and configuration. This would end up with less code as well and less headaches when using api.
  15. Oliver Hader commented on patch set 19 11/23/25, 18:12

    Reply Unresolved

    I did not know about that annotation, it seems to be really useful. Thanks for sharing!
  16. Markus Klein commented on patch set 19 11/23/25, 20:23

    Sincere thanks for all your thoughts and reviews and taking the time! My sole point is the absolute MESS we have in this area. Having the exact same arguements in 4-5 places, and their parsing as well is IMHO the absolute worst solution we can have. No matter which direction you think this should go, we MUST ensure that any future change does not again only change 50% of the viewhelpers. Being it descriptions or feature adjustments. The sole insufficience of the current situation is proven how changes were done poorly in the past, due to unawareness of the code duplications, I assume. I'm, by no means, offended or so, if my proposal is disregarded. I just don't know any better way in PHP to structure this shared code than using "composition" in the form of traits. I'll refrain from further anwering all points made with my thoughts, but I'm open to any fruitful discussion; maybe in Slack?! My message: It is absolutely a shame and embarrassing, that one of the most basic functionalities of the core since decades (page types) is not even fully functional by Extbase's UriBuilder. My goal initially was to get that somehow working, in a sane way... until I took a deep dive into those ViewHelpers.
  17. Markus Klein commented on patch set 19 11/23/25, 20:33

    Reply

    Of course, one more thing I forgot: Another proof of the existing madness: It took me more than a working day alone to only validate all the arguments and their handling one by one and to decide, which version of it is the most correct one. I was two times at a point were I the "is it worth"-thought came around. In the end I decided to finalize my version, because "hey, somebody has to try at lest" and "okay, at least one 'bigger' contribution to making v14 better, from me." 😉
  18. Christian Kuhn commented on patch set 19 11/23/25, 20:59

    Reply

    i agree we can improve. maybe we could have a chat to see what can be done, to for instance see if the argument streamlining can be extracted.
  19. Christian Kuhn wrote 06/18/26, 23:12

    Removed reviewer Christian Kuhn with the following votes: * Code-Review-1 by Christian Kuhn
  20. Benni Mack uploaded patch set 20 CR +1 V +1 11/11/26, 10:33

  21. Benni Mack uploaded patch set 21 11/11/26, 10:34

  22. core-ci voted on patch set 20 V +1 11/11/26, 10:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/114048

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

  24. Markus Klein commented on patch set 21 CR -1 11/11/26, 11:54

    I need to verify this again, if the solution is still correct
  25. Benni Mack marked it work in progress 11/11/26, 15:18