BeforeDatabaseRecordLinkResolvedEvent 

New in version 14.0

The event BeforeDatabaseRecordLinkResolvedEvent has been introduced to retrieve records via custom code in \TYPO3\CMS\Frontend\Typolink\DatabaseRecordLinkBuilder .

The PSR-14 event \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 $record set to null. If an event listener retrieves a record from the database, it should set the $record property to the record as an array. This will stop the event propagation and cause the default record retrieval logic in \TYPO3\CMS\Frontend\Typolink\DatabaseRecordLinkBuilder to be skipped.

Note that the custom code needs to take care - if relevant - of all aspects normally handled by \TYPO3\CMS\Frontend\Typolink\DatabaseRecordLinkBuilder , such as record visibility, language overlay or version overlay.

Example 

EXT:my_extension/Classes/Frontend/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Frontend\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Frontend\Event\BeforeDatabaseRecordLinkResolvedEvent;

final readonly 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 (just an example -
        // replace the code in the first line below with your code)
        $result = getADatabaseRecord();
        if ($result !== false) {
            // Setting the record stops event propagation and
            // skips the default record retrieval logic
            $event->record = $result;
        }
    }
}
Copied!

API 

class BeforeDatabaseRecordLinkResolvedEvent
Fully qualified name
\TYPO3\CMS\Frontend\Event\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.

public readonly linkDetails

Information about the link being processed

public readonly databaseTable

The name of the database the record belongs to

public readonly typoscriptConfiguration

The full TypoScript link handler configuration

public readonly tsConfig

The full TSconfig link handler configuration

public readonly request

The current request object

public readonly record

The database record as an array (initially null)