Feature: #102745 - PSR-14 events for modifying ContentObject stdWrap functionality

See forge#102745

Description

Four new PSR-14 events have been introduced:

  • \TYPO3\CMS\Frontend\ContentObject\Event\BeforeStdWrapFunctionsInitializedEvent

  • \TYPO3\CMS\Frontend\ContentObject\Event\AfterStdWrapFunctionsInitializedEvent

  • \TYPO3\CMS\Frontend\ContentObject\Event\BeforeStdWrapFunctionsExecutedEvent

  • \TYPO3\CMS\Frontend\ContentObject\Event\AfterStdWrapFunctionsExecutedEvent

They serve as more powerful replacement of the removed, $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['stdWrap'] hook.

Instead of registering one hook class, implementing four different methods - due to the deprecated interface - extension authors are now able to register dedicated listeners. Next to the individual events, it's also possible to register listeners to listen on the parent \TYPO3\CMS\Frontend\ContentObject\Event\EnhanceStdWrapEvent. Since this event is extended by all other events, registered listeners are called on each occurrence.

All events provide the same functionality. The difference is only the execution order in which they are called in the stdWrap processing chain.

Available methods:

  • getContent() - Returns the current content (stdWrap result)

  • setContent() - Allows to modify the final content (stdWrap result)

  • getConfiguration() - Returns the corresponding TypoScript configuration

  • 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\AfterStdWrapFunctionsExecutedEvent;
use TYPO3\CMS\Frontend\ContentObject\Event\AfterStdWrapFunctionsInitializedEvent;
use TYPO3\CMS\Frontend\ContentObject\Event\BeforeStdWrapFunctionsInitializedEvent;
use TYPO3\CMS\Frontend\ContentObject\Event\EnhanceStdWrapEvent;

final class EnhanceStdWrapEventListener
{
    #[AsEventListener]
    public function __invoke(EnhanceStdWrapEvent $event): void
    {
        // listen to all events
    }

    #[AsEventListener]
    public function individualListener(BeforeStdWrapFunctionsInitializedEvent $event): void
    {
        // listen on BeforeStdWrapFunctionsInitializedEvent only
    }

    #[AsEventListener]
    public function listenOnMultipleEvents(AfterStdWrapFunctionsInitializedEvent|AfterStdWrapFunctionsExecutedEvent $event): void
    {
        // Union type to listen to different events
    }
}

Impact

Using the new PSR-14 events, it's now possible to fully influence the stdWrap functionality in TYPO3's Core API class \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer.

Using the new individual events, developers are now also able to simplify their code by just listening for the relevant parts in the stdWrap processing.