ModifyClearCacheActionsEvent
New in version 11.4
The PSR-14 event
\TYPO3\
is fired in the
\TYPO3\
class and allows extension authors to modify the clear cache actions, shown
in the TYPO3 backend top toolbar.
The event can be used to change or remove existing clear cache
actions, as well as to add new actions. Therefore, the event also
contains, next to the usual "getter" and "setter" methods, the convenience
method
add
for the
cache
and
cache
arrays.
Example
Registration of the event listener in the extension's Services.
:
services:
# Place here the default dependency injection configuration
MyVendor\MyExtension\Backend\EventListener\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/toolbar/my-event-listener'
Read how to configure dependency injection in extensions.
The corresponding event listener class:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Backend\EventListener;
use TYPO3\CMS\Backend\Backend\Event\ModifyClearCacheActionsEvent;
final class MyEventListener
{
public function __invoke(ModifyClearCacheActionsEvent $event): void
{
// do magic here
}
}
The cache action array element consists of the following keys and values:
$event->addCacheAction([
// Required keys:
'id' => 'pages',
'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:flushPageCachesTitle',
'href' => (string)$uriBuilder->buildUriFromRoute('tce_db', ['cacheCmd' => 'pages']),
'iconIdentifier' => 'actions-system-cache-clear-impact-low',
// Optional, recommended keys:
'description' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:flushPageCachesDescription',
'severity' => 'success',
]);
The key
severity
can contain one of these strings: notice, info, success, warning, error
.
The cache identifier array is a numerical array in which the array value corresponds to the registered id
of the cache action array.
Here is an example of how to use it for a custom cache action:
$myIdentifier = 'myExtensionCustomStorageCache';
$event->addCacheAction([
'id' => $myIdentifier,
'title' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:CacheActionTitle',
// Note to register your own route, this is an example
'href' => (string)$uriBuilder->buildUriFromRoute('ajax_' . $myIdentifier . '_purge'),
'iconIdentifier' => 'actions-system-cache-clear-impact-low',
'description' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:CacheActionDescription',
'severity' => 'notice',
]);
$event->addCacheActionIdentifier($myIdentifier);
API
- class ModifyClearCacheActionsEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Backend\ Backend\ Event\ Modify Clear Cache Actions Event
An event to modify the clear cache actions, shown in the TYPO3 Backend top toolbar
- addCacheActionIdentifier ( string $cacheActionIdentifier)
-
- param $cacheActionIdentifier
-
the cacheActionIdentifier