Feature: #107679 - PSR-14 event for custom record retrieval in LinkBuilder
See forge#107679
Description
A new PSR-14 event
\TYPO3\
has been introduced to retrieve a record using custom code in the
\TYPO3\.
The event is dispatched with
$record set to
null.
If an event listener retrieves a record from the database, it can assign the
record as an array to
$record. Doing so stops event propagation and skips
the default record retrieval logic in
\TYPO3\.
Important
The event is stoppable: Setting
$record to a non-null value stops
propagation and disables the default record lookup.
Custom event listeners must handle all aspects normally performed by
Database, such as record visibility, language overlay,
or version overlay, if relevant.
The event provides the following public properties (all read-only, except for
$record):
$link: Information about the link being processed.Details $database: The name of the database table the record belongs to.Table $typoscript: The full TypoScript link handler configuration.Configuration $ts: The full TSconfig link handler configuration.Config $request: The current request object.$record: The database record as an array (initiallynull).
Example
An example event listener could look like:
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Frontend\Event\BeforeDatabaseRecordLinkResolvedEvent;
final class MyEventListener
{
#[AsEventListener(
identifier: 'my-extension/before-database-record-link-resolved',
)]
public function __invoke(BeforeDatabaseRecordLinkResolvedEvent $event): void
{
// Retrieve the record from the database as an array
$result = /* ... */;
if ($result !== false) {
// Setting the record stops event propagation and
// skips the default record retrieval logic
$event->record = $result;
}
}
}
Impact
This new event allows developers to implement custom record retrieval logic for links created with typolink, for example to apply custom access restrictions or fetch data from alternative sources before rendering a link.