[!!!][FEATURE] Introduce dedicated class to create typolinks with unified Event
This change moves all "typolink" functionality from cObj->typolink into a custom "LinkFactory" class which then calls custom LinkBuilders (as before) to do their work. The main benefit is separation of concerns, thinning out functionality from the monster ContentObjectRenderer functionality. Instead of the global hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typoLink_PostProc'] a new PSR-14 Event "AfterLinkIsGeneratedEvent" is introduced, which in turn uses the LinkResult to operate on. This new Event also makes the hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['urlProcessing']['urlProcessors'] obsolete, which was used for non-page links + URLs. As all functionality for frontend links are now running through this event, which contains all information. In addition, typolink.userFunc now receives a LinkResult object instead of a <a> string with arguments, and needs to return a LinkResult object again. Also, the ATagParams hook vanished as well, since the new Event can be used easily (and in a much better way!) Both parts are breaking, all other parts are expected to work as before. A new HtmlLinkResult is added, which allows for building a HSC'ed <a> tag properly in typolink(). Architectural Details: * LinkFactory (new class) is now handling the "typolink" logic for creating any kind of links or URLs (page/mails/files). For the actual logic of e.g, pages the "PageLinkBuilder" is used in this place. * Internally, LinkFactory follows the same generation as cObj->typolink() before, but uses methods to make the code more readable. * In the end, LinkFactory will return a "LinkResultInterface" which contains everything to build a <a> tag, however it cannot return a "UriInterface" from PSR-7, as a link to mailto: is not a URL, thus, not supported by PSR-7. * The main "cObj->typolink()" method then takes the LinkResultInterface and wraps it into a HtmlLinkResult which does a htmlspecialchars() around all the attributes and the $linkText. So this is still the way to go to use from a public API point of view. * As typolink() heavily depends on stdWrap() and thus on cObject this information needs to be injected properly of course, and has the hard dependency when creating links in the Frontend. * new methods $cObj->createUrl() and $cObj->createLink() are added to make use of the LinkInterface functionality programmatically, so people can choose to get a hsc'ed result via typolink(), or typolink_URL(), or a pure data via createUrl() and createLink(). Next steps / further patches: * Deprecate "lastTypoLink_LD" etc. * Move LinkResultFactory into LinkFactory with ClassAlias * Maybe add another method to just generate an URL to the LinkFactory * Create JsonLinkResult object and clean up original LinkResult object Resolves: #96641 Resolves: #92029 Releases: main Change-Id: Ic9ce01153a0cfdcbacb15e1e3f3e382f95400192 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72999 Tested-by:core-ci <typo3@b13.com> Tested-by:
Oliver Hader <oliver.hader@typo3.org> Tested-by:
Stefan Bürk <stefan@buerk.tech> Tested-by:
Oliver Bartsch <bo@cedev.de> Reviewed-by:
Oliver Hader <oliver.hader@typo3.org> Reviewed-by:
Stefan Bürk <stefan@buerk.tech> Reviewed-by:
Oliver Bartsch <bo@cedev.de>
Showing
- Build/phpstan/phpstan-baseline.neon 1 addition, 16 deletionsBuild/phpstan/phpstan-baseline.neon
- typo3/sysext/core/Classes/LinkHandling/LinkService.php 2 additions, 0 deletionstypo3/sysext/core/Classes/LinkHandling/LinkService.php
- typo3/sysext/core/Documentation/Changelog/12.0/Breaking-96641-TypoLinkRelatedHooksRemoved.rst 55 additions, 0 deletions...gelog/12.0/Breaking-96641-TypoLinkRelatedHooksRemoved.rst
- typo3/sysext/core/Documentation/Changelog/12.0/Deprecation-96641-LinkRelatedFunctionalityInContentObjectRenderer.rst 56 additions, 0 deletions...96641-LinkRelatedFunctionalityInContentObjectRenderer.rst
- typo3/sysext/core/Documentation/Changelog/12.0/Deprecation-96641-UnusedHookRelatedUrlProcessorInterface.rst 44 additions, 0 deletions...recation-96641-UnusedHookRelatedUrlProcessorInterface.rst
- typo3/sysext/core/Documentation/Changelog/12.0/Feature-96641-NewPSR-14EventForModifyingLinks.rst 70 additions, 0 deletions...og/12.0/Feature-96641-NewPSR-14EventForModifyingLinks.rst
- typo3/sysext/extbase/Classes/Mvc/Web/Routing/UriBuilder.php 1 addition, 4 deletionstypo3/sysext/extbase/Classes/Mvc/Web/Routing/UriBuilder.php
- typo3/sysext/extbase/Tests/Unit/Mvc/Web/Routing/UriBuilderTest.php 6 additions, 6 deletions...ext/extbase/Tests/Unit/Mvc/Web/Routing/UriBuilderTest.php
- typo3/sysext/fluid/Classes/ViewHelpers/Link/EmailViewHelper.php 9 additions, 9 deletions...sysext/fluid/Classes/ViewHelpers/Link/EmailViewHelper.php
- typo3/sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php 1 addition, 1 deletion.../sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php
- typo3/sysext/fluid/Classes/ViewHelpers/Link/TypolinkViewHelper.php 1 addition, 1 deletion...ext/fluid/Classes/ViewHelpers/Link/TypolinkViewHelper.php
- typo3/sysext/fluid/Classes/ViewHelpers/Uri/TypolinkViewHelper.php 1 addition, 1 deletion...sext/fluid/Classes/ViewHelpers/Uri/TypolinkViewHelper.php
- typo3/sysext/fluid/Tests/Functional/ViewHelpers/Link/TypolinkViewHelperTest.php 6 additions, 6 deletions...ts/Functional/ViewHelpers/Link/TypolinkViewHelperTest.php
- typo3/sysext/form/Classes/Domain/Finishers/RedirectFinisher.php 1 addition, 1 deletion...sysext/form/Classes/Domain/Finishers/RedirectFinisher.php
- typo3/sysext/form/Tests/Unit/Domain/Finishers/RedirectFinisherTest.php 1 addition, 4 deletions...form/Tests/Unit/Domain/Finishers/RedirectFinisherTest.php
- typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php 111 additions, 351 deletions.../frontend/Classes/ContentObject/ContentObjectRenderer.php
- typo3/sysext/frontend/Classes/ContentObject/ImageContentObject.php 1 addition, 1 deletion...ext/frontend/Classes/ContentObject/ImageContentObject.php
- typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php 1 addition, 1 deletion...ntend/Classes/Controller/TypoScriptFrontendController.php
- typo3/sysext/frontend/Classes/Event/AfterLinkIsGeneratedEvent.php 63 additions, 0 deletions...sext/frontend/Classes/Event/AfterLinkIsGeneratedEvent.php
- typo3/sysext/frontend/Classes/Http/UrlProcessorInterface.php 1 addition, 0 deletionstypo3/sysext/frontend/Classes/Http/UrlProcessorInterface.php
Please register or sign in to comment