Feature: #108726 - Add PSR-14 Events ModifyRenderedContentAreaEvent and ModifyRenderedRecordEvent 

See forge#108726

Description 

With the \TYPO3\CMS\Fluid\Event\ModifyRenderedContentAreaEvent, developers can intercept the rendering of content areas in Fluid templates to modify the output. This depends on content areas being rendered with the new <f:render.contentArea> ViewHelper in Fluid templates, see Introduce Fluid f:render.contentArea ViewHelper.

With the \TYPO3\CMS\Fluid\Event\ModifyRenderedRecordEvent, developers can intercept the rendering of individual records in Fluid templates to modify the output. This depends on records being rendered with the new <f:render.contentArea> or <f:render.record> ViewHelpers in Fluid templates, see Introduce Fluid f:render.record ViewHelper.

Note that any alterations will be output as-is and will not be escaped. If you process insecure content within an event listener, be sure to escape it properly, e.g. by applying htmlspecialchars() to it.

Example 

An example event listener could look like this:

EXT:my_extension/Classes/EventListener/ModifyRenderedContentEventListener.php
namespace MyVendor\MyExtension\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Fluid\Event\ModifyRenderedContentAreaEvent;
use TYPO3\CMS\Fluid\Event\ModifyRenderedRecordEvent;

final class ModifyRenderedContentEventListener
{
    #[AsEventListener]
    public function modifyContentArea(ModifyRenderedContentAreaEvent $event): void
    {
        $content = 'before area<hr />'. $event->getRenderedContentArea() . '<hr />after area';
        $event->setRenderedContentArea($content);
    }

    #[AsEventListener]
    public function modifyRecord(ModifyRenderedRecordEvent $event): void
    {
        $content = 'before record<hr />'. $event->getRenderedRecord() . '<hr />after record';
        $event->setRenderedRecord($content);
    }
}
Copied!

Impact 

The new events can be used by extension authors to enhance the output of content areas and records rendered in themes.