BeforeStdWrapContentStoredInCacheEvent¶
New in version 13.0
This event serves as a more powerful replacement for the removed hook
$GLOBALS
.
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¶
<?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\
has been
introduced to tag a PHP class as an event listener. Alternatively, you can also
register an event listener via the Configuration/
file. Have
a look into the section Implementing an event listener in your extension.
API¶
- 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.
- 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
-
\TYPO3\
CMS\ Frontend\ Content Object\ Content Object Renderer