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¶
<?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');
}
}
}
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 \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 ( ) ¶
-
- returntype
-
string
- setContent ( string $content) ¶
-
- param string $content
-
the content
- getTags ( ) ¶
-
- returntype
-
array
- setTags ( array $tags) ¶
-
- param array $tags
-
the tags
- getKey ( ) ¶
-
- returntype
-
string
- setKey ( string $key) ¶
-
- param string $key
-
the key
- getLifetime ( ) ¶
-
- returntype
-
int
- setLifetime ( int $lifetime) ¶
-
- param int $lifetime
-
the lifetime
- getConfiguration ( ) ¶
-
- returntype
-
array
- getContentObjectRenderer ( ) ¶
-
- returntype
-
TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer