BeforeDatabaseRecordLinkResolvedEvent
New in version 14.0
The event
Before
has been introduced to retrieve records via custom code in
\TYPO3\.
The PSR-14 event
\TYPO3\
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\ to be skipped.
Important
The event is stoppable: Setting the
$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
\TYPO3\,
such as record visibility, language overlay or version overlay.
Example: Retrieve the record of a link yourself
<?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;
}
}
}
API
-
final class
BeforeDatabaseRecordLinkResolvedEvent -
- Fully qualified name
-
\TYPO3\CMS\ Frontend\ Event\ Before Database Record Link Resolved Event
Event dispatched before the DatabaseRecordLinkBuilder resolves a database record.
This event is stoppable: If an event listener sets a record, the event propagation will be stopped and the default record retrieval logic will be skipped.