From 36752907044857ea1869ea9aef00ce8597ab149f Mon Sep 17 00:00:00 2001 From: Sarah McCarthy Date: Wed, 3 Dec 2025 13:06:32 +0100 Subject: [PATCH 1/2] [FEATURE] Add PSR-14 for record retrieval in DatabaseRecordLinkBuilder Resolves: https://github.com/TYPO3-Documentation/Changelog-To-Doc/issues/1405 Releases: main --- .../BeforeDatabaseRecordLinkResolvedEvent.rst | 59 +++++++++++++++++++ .../_MyEventListener.php | 26 ++++++++ ...oreDatabaseRecordLinkResolvedEvent.rst.txt | 30 ++++++++++ 3 files changed, 115 insertions(+) create mode 100644 Documentation/ApiOverview/Events/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst create mode 100644 Documentation/ApiOverview/Events/Events/Frontend/_BeforeDatabaseRecordLinkResolvedEvent/_MyEventListener.php create mode 100644 Documentation/CodeSnippets/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst.txt diff --git a/Documentation/ApiOverview/Events/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst b/Documentation/ApiOverview/Events/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst new file mode 100644 index 0000000000..4bb16aea36 --- /dev/null +++ b/Documentation/ApiOverview/Events/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst @@ -0,0 +1,59 @@ +.. include:: /Includes.rst.txt +.. index:: Events; BeforeDatabaseRecordLinkResolvedEvent +.. _BeforeDatabaseRecordLinkResolvedEvent: + +===================================== +BeforeDatabaseRecordLinkResolvedEvent +===================================== + +.. versionadded:: 14.0 + The event :php-short:`TYPO3\CMS\Frontend\Event\BeforeDatabaseRecordLinkResolvedEvent` + has been introduced to retrieve records via custom code in + :php:`TYPO3\CMS\Frontend\Typolink\DatabaseRecordLinkBuilder`. + +The PSR-14 event :php:`TYPO3\CMS\Frontend\Event\BeforeDatabaseRecordLinkResolvedEvent` +is dispatched immediately before database record lookup is done +for a link by the DatabaseRecordLinkBuilder and therefore allows +custom functionality to be attached to record retrieval. The event is stoppable, +which means that as soon as a listener returns a record, no further listener +gets called and the core does no further lookup. + +The event is dispatched with :php:`$record` set to :php:`null`. If an event +listener retrieves a record from the database, it should set the :php:`$record` +property to the record as an array. This will stop the event propagation and +cause the default record retrieval logic in +:php:`TYPO3\CMS\Frontend\Typolink\DatabaseRecordLinkBuilder` to be skipped. + +.. important:: + + The event is stoppable: Setting the :php:`$record` property to a non-null + value stops event propagation and skips the default record retrieval logic. + +Note that the custom code needs to take care - if relevant - of all aspects +normally handled by :php:`TYPO3\CMS\Frontend\Typolink\DatabaseRecordLinkBuilder`, +such as record visibility, language overlay or version overlay. + +The event provides access to the following public properties: + +* :php:`$linkDetails`: Information about the link being processed +* :php:`$databaseTable`: The name of the database the record belongs to +* :php:`$typoscriptConfiguration`: The full TypoScript link handler configuration +* :php:`$tsConfig`: The full TSconfig link handler configuration +* :php:`$request`: The current request object +* :php:`$record`: The database record as an array (initially :php:`null`) + +.. _BeforeDatabaseRecordLinkResolvedEvent-example: + +Example +======= + +.. literalinclude:: _BeforeDatabaseRecordLinkResolvedEvent/_MyEventListener.php + :language: php + :caption: EXT:my_extension/Classes/Frontend/EventListener/MyEventListener.php + +.. _BeforeDatabaseRecordLinkResolvedEvent-api: + +API +=== + +.. include:: /CodeSnippets/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst.txt diff --git a/Documentation/ApiOverview/Events/Events/Frontend/_BeforeDatabaseRecordLinkResolvedEvent/_MyEventListener.php b/Documentation/ApiOverview/Events/Events/Frontend/_BeforeDatabaseRecordLinkResolvedEvent/_MyEventListener.php new file mode 100644 index 0000000000..920c0d4898 --- /dev/null +++ b/Documentation/ApiOverview/Events/Events/Frontend/_BeforeDatabaseRecordLinkResolvedEvent/_MyEventListener.php @@ -0,0 +1,26 @@ +record = $result; + } + } +} diff --git a/Documentation/CodeSnippets/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst.txt b/Documentation/CodeSnippets/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst.txt new file mode 100644 index 0000000000..6dc4bfa21b --- /dev/null +++ b/Documentation/CodeSnippets/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst.txt @@ -0,0 +1,30 @@ +.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets +.. php:namespace:: TYPO3\CMS\Frontend\Event + +.. php:class:: BeforeDatabaseRecordLinkResolvedEvent + + A PSR-14 event fired in the frontend process before database record + lookup is done for a link. + + This event makes it possible to implement custom logic, for example, + for specific frontend access when retrieving a linked record in a typolink. + + .. php:attr:: linkDetails + :readonly: + :public: + + .. php:attr:: databaseTable + :readonly: + :public: + + .. php:attr:: typoscriptConfiguration + :readonly: + :public: + + .. php:attr:: request + :readonly: + :public: + + .. php:attr:: record + :readonly: + :public: From de59ed5c0ffc943b2fcf2de621763f936ffb4597 Mon Sep 17 00:00:00 2001 From: Sarah McCarthy Date: Thu, 4 Dec 2025 16:04:56 +0100 Subject: [PATCH 2/2] [TASK] Incorporate review Releases: main --- .../BeforeDatabaseRecordLinkResolvedEvent.rst | 9 --------- ...BeforeDatabaseRecordLinkResolvedEvent.rst.txt | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Documentation/ApiOverview/Events/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst b/Documentation/ApiOverview/Events/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst index 4bb16aea36..7cb2a51d4c 100644 --- a/Documentation/ApiOverview/Events/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst +++ b/Documentation/ApiOverview/Events/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst @@ -33,15 +33,6 @@ Note that the custom code needs to take care - if relevant - of all aspects normally handled by :php:`TYPO3\CMS\Frontend\Typolink\DatabaseRecordLinkBuilder`, such as record visibility, language overlay or version overlay. -The event provides access to the following public properties: - -* :php:`$linkDetails`: Information about the link being processed -* :php:`$databaseTable`: The name of the database the record belongs to -* :php:`$typoscriptConfiguration`: The full TypoScript link handler configuration -* :php:`$tsConfig`: The full TSconfig link handler configuration -* :php:`$request`: The current request object -* :php:`$record`: The database record as an array (initially :php:`null`) - .. _BeforeDatabaseRecordLinkResolvedEvent-example: Example diff --git a/Documentation/CodeSnippets/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst.txt b/Documentation/CodeSnippets/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst.txt index 6dc4bfa21b..cacec6036d 100644 --- a/Documentation/CodeSnippets/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst.txt +++ b/Documentation/CodeSnippets/Events/Frontend/BeforeDatabaseRecordLinkResolvedEvent.rst.txt @@ -13,18 +13,34 @@ :readonly: :public: + Information about the link being processed + .. php:attr:: databaseTable :readonly: :public: + The name of the database the record belongs to + .. php:attr:: typoscriptConfiguration :readonly: :public: + The full TypoScript link handler configuration + + .. php:attr:: tsConfig + :readonly: + :public: + + The full TSconfig link handler configuration + .. php:attr:: request :readonly: :public: + The current request object + .. php:attr:: record :readonly: :public: + + The database record as an array (initially :php:`null`)