Feature: #110815 - PSR-14 event after a record is rendered
See forge#110815
Description
The new PSR-14 event
\TYPO3\
is dispatched by the
CONTENT
and
RECORDS
content objects after each single record has been rendered. It allows
modifying the rendered content of the record, for example to wrap it in
additional markup.
It is the counterpart to
\TYPO3\, which is
dispatched for records rendered with the
<f: and
<f: ViewHelpers.
The event provides the following methods:
getRendered Record () - Returns the rendered content of the record.
setRendered Record () - Replaces the rendered content of the record. Make sure to return escaped content if necessary.
getRecord () - Returns the rendered record as
\TYPO3\, likeCMS\ Core\ Domain\ Record Interface Modifydoes. This is usually a resolved record. If the row cannot be resolved, for example because a customRendered Record Event select.omits system fields such as the language or workspace fields, aselect Fields \TYPO3\holding the unprocessed row is provided instead.CMS\ Core\ Domain\ Raw Record getRequest () - Returns the current request.
The event is not dispatched for tables without TCA, or if a custom
select. omits the type field of the table, since
no record object can be created then. The rendered content of such records
is returned unmodified.
Example
namespace MyVendor\MyExtension\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Frontend\ContentObject\Event\AfterRecordIsRenderedEvent;
final class WrapRenderedRecord
{
#[AsEventListener]
public function __invoke(AfterRecordIsRenderedEvent $event): void
{
if ($event->getRecord()->getMainType() !== 'tt_content') {
return;
}
$event->setRenderedRecord(
'<div class="my-record">' . $event->getRenderedRecord() . '</div>'
);
}
}
Impact
Listeners can modify the output of every record rendered by the
CONTENT
and
RECORDS
content objects, for
example the content elements of a page rendered with
styles..