Feature: #102614 - PSR-14 event for modifying GetData result

See forge#102614

Description

A new PSR-14 event \TYPO3\CMS\Frontend\ContentObject\Event\AfterGetDataResolvedEvent has been introduced which serves as a drop-in replacement for the now removed hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['getData'].

The event is being dispatched just before ContentObjectRenderer->getData() is about to return the resolved "data". The event is therefore in comparison to the removed hook not dispatched for every section of the parameter string, but only once, making the former $secVal superfluous.

To modify the getData() result, the following methods are available:

  • setResult(): Allows to set the "data" to return

  • getResult(): Returns the resolved "data"

  • getParameterString(): Returns the parameter string, e.g. field : title

  • getAlternativeFieldArray(): Returns the alternative field array, if provided

  • getContentObjectRenderer(): Returns the current ContentObjectRenderer instance

Example

The event listener class, using the PHP attribute #[AsEventListener] for registration:

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Frontend\ContentObject\Event\AfterGetDataResolvedEvent;

final class AfterGetDataResolvedEventListener
{
    #[AsEventListener]
    public function __invoke(AfterGetDataResolvedEvent $event): void
    {
        $event->setResult('modified-result');
    }
}

Impact

Using the new PSR-14 event, it's now possible to modify the resolved getData() result.