BeforeStdWrapContentStoredInCacheEvent

New in version 13.0

This event serves as a more powerful replacement for the removed hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['stdWrap_cacheStore'].

The PSR-14 event \TYPO3\CMS\Frontend\ContentObject\Event\BeforeStdWrapContentStoredInCacheEvent is dispatched just before the final stdWrap content is added to the cache. It allows to fully manipulate the $content to be added, the cache $tags to be used, as well as the corresponding cache $key and the cache $lifetime.

Additionally, the new event provides the full TypoScript configuration and the current ContentObjectRenderer instance.

Example

EXT:my_extension/Classes/Frontend/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Frontend\EventListener;

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

#[AsEventListener(
    identifier: 'my-extension/before-stdwrap-content-stored-in-cache',
)]
final readonly class MyEventListener
{
    public function __invoke(BeforeStdWrapContentStoredInCacheEvent $event): void
    {
        if (in_array('foo', $event->getTags(), true)) {
            $event->setContent('modified-content');
        }
    }
}
Copied!

New in version 13.0

The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, you can also register an event listener via the Configuration/Services.yaml file. Have a look into the section Implementing an event listener in your extension.

API

class BeforeStdWrapContentStoredInCacheEvent
Fully qualified name
\TYPO3\CMS\Frontend\ContentObject\Event\BeforeStdWrapContentStoredInCacheEvent

Listeners to this Event are able to modify the final stdWrap content and corresponding cache tags, before being stored in cache.

Additionally, listeners are also able to change the cache key to be used as well as the lifetime. Therefore, the whole configuration is available.

getContent ( )
Returns
?string
setContent ( string $content)
param $content

the content

getTags ( )
Returns
array
setTags ( array $tags)
param $tags

the tags

getKey ( )
Returns
string
setKey ( string $key)
param $key

the key

getLifetime ( )
Returns
?int
setLifetime ( ?int $lifetime)
param $lifetime

the lifetime

getConfiguration ( )
Returns
array
getContentObjectRenderer ( )
Returns
TYPO3CMSFrontendContentObjectContentObjectRenderer