BeforeStdWrapContentStoredInCacheEvent
The PSR-14 event
\TYPO3\
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
Content instance.
Example: Replace content that has a cache tag
<?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');
}
}
}
API
-
final class
BeforeStdWrapContentStoredInCacheEvent -
- Fully qualified name
-
\TYPO3\CMS\ Frontend\ Content Object\ Event\ Before Std Wrap Content Stored In Cache Event
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.