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\ Content Object\ Event\ Before Std Wrap Functions Initialized Event \TYPO3\
CMS\ Frontend\ Content Object\ Event\ After Std Wrap Functions Initialized Event \TYPO3\
CMS\ Frontend\ Content Object\ Event\ Before Std Wrap Functions Executed Event \TYPO3\
CMS\ Frontend\ Content Object\ Event\ After Std Wrap Functions Executed Event
They serve as more powerful replacement of the removed,
$GLOBALS
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\
. 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:
get
- Returns the current content (stdWrap result)Content () set
- Allows to modify the final content (stdWrap result)Content () get
- Returns the corresponding TypoScript configurationConfiguration () get
- Returns the currentContent Object Renderer () Content
instanceObject Renderer
Example
The event listener class, using the PHP attribute #
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\
.
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.