Feature: #97862 - New PSR-14 events for manipulating frontend page generation and cache behaviour
See forge#97862
Description
Two new PSR-14 events have been added:
\TYPO3\
CMS\ Frontend\ Event\ After Cacheable Content Is Generated Event \TYPO3\
CMS\ Frontend\ Event\ After Cached Page Is Persisted Event
They are added in favor of the removed hooks:
$GLOBALS
['TYPO3_ CONF_ VARS'] ['SC_ OPTIONS'] ['tslib/ class. tslib_ fe. php'] ['content Post Proc- cached'] $GLOBALS
['TYPO3_ CONF_ VARS'] ['SC_ OPTIONS'] ['tslib/ class. tslib_ fe. php'] ['content Post Proc- all'] $GLOBALS
['TYPO3_ CONF_ VARS'] ['SC_ OPTIONS'] ['tslib/ class. tslib_ fe. php'] ['use Page Cache'] $GLOBALS
['TYPO3_ CONF_ VARS'] ['SC_ OPTIONS'] ['tslib/ class. tslib_ fe. php'] ['insert Page Incache']
Both events are called when the content of a page has been generated in the TYPO3 Frontend.
Example
Registration of the After
in your extension's Services.
:
MyVendor\MyPackage\Backend\MyEventListener:
tags:
- name: event.listener
identifier: 'my-package/content-modifier'
The corresponding event listener class:
use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;
class MyEventListener {
public function __invoke(AfterCacheableContentIsGeneratedEvent $event): void
{
// Only do this when caching is enabled
if (!$event->isCachingEnabled()) {
return;
}
$event->getController()->content = str_replace('foo', 'bar', $event->getController()->content);
}
}
Impact
The event After
can be used
to decide if a page should be stored in cache and is executed right after
all cacheable content is generated. It can also be used to manipulate
the content before it is stored in TYPO3's page cache. The event is used
in indexed search to index cacheable content.
The After
contains the
information if a generated page is able to store in cache via the
$event->is
method. This can be used to
differentiate between the previous hooks content
and
content
(do something regardless if caching is enabled or not).
The After
is commonly used to
generate a static file cache. This event is only called if the
page was actually stored in TYPO3's page cache.