Feature: #99323 - PSR-14 event for modifying records after fetching content
See forge#99323
Description
A new PSR-14 event \TYPO3\
has been introduced which serves as a more powerful replacement for the now
removed
$GLOBALS
hook.
The event allows to modify the fetched records next to the possibility to
manipulate most of the options, such as slide
. Listeners are also able
to set the final content and change the whole TypoScript configuration,
used for further processing.
This can be achieved with the following methods:
get
Records () get
Final Content () get
Slide () get
Slide Collect () get
Slide Collect Reverse () get
Slide Collect Fuzzy () get
Configuration () set
Records () set
Final Content () set
Slide () set
Slide Collect () set
Slide Collect Reverse () set
Slide Collect Fuzzy () set
Configuration ()
Example
The event listener class, using the PHP attribute #
for
registration:
use TYPO3\CMS\Frontend\ContentObject\Event\ModifyRecordsAfterFetchingContentEvent;
final class ModifyRecordsAfterFetchingContentEventListener
{
#[AsEventListener]
public function __invoke(ModifyRecordsAfterFetchingContentEvent $event): void
{
if ($event->getConfiguration()['table'] !== 'tt_content') {
return;
}
$records = array_reverse($event->getRecords());
$event->setRecords($records);
}
}
Impact
Using the new PSR-14 event, it's now possible to modify the records fetched by the "Content" ContentObject, before they are being further processed, or even skip TYPO3's default processing of records by setting an empty array for the records to be rendered.
Additionally, next to the final content, also most of the options and the whole TypoScript configuration can be modified.