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
<?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
- class BeforeDatabaseRecordLinkResolvedEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Frontend\ Event\ Before Database Record Link Resolved Event
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.