Commit 86834cb1 authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Benni Mack
Browse files

[FEATURE] Introduce ModifyClearCacheActionsEvent

A new PSR-14 based event "ModifyClearCacheActionsEvent"
is introduced in favour of the existing
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions']
hook, which is now marked as deprecated, along with
its interface "ClearCacheActionsHookInterface".

The new event features the same functionality as
the hook. Additionally a new convenience method
`add` is available for the class properties, allowing
extension authors to add their custom actions more
easily. This might be the most common use case for
using this event.

Resolves: #95083
Releases: master
Change-Id: I1e621a00b04cdf43978a6e982b66c397e9437a29
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70870

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 412df9f4
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Backend\Backend\Event;
/**
* An event to modify the clear cache actions, shown in the TYPO3 Backend top toolbar
*/
final class ModifyClearCacheActionsEvent
{
private array $cacheActions;
private array $cacheActionIdentifiers;
public function __construct(array $cacheActions, array $cacheActionIdentifiers)
{
$this->cacheActions = $cacheActions;
$this->cacheActionIdentifiers = $cacheActionIdentifiers;
}
public function addCacheAction(array $cacheAction): void
{
$this->cacheActions[] = $cacheAction;
}
public function setCacheActions(array $cacheActions): void
{
$this->cacheActions = $cacheActions;
}
public function getCacheActions(): array
{
return $this->cacheActions;
}
public function addCacheActionIdentifier(string $cacheActionIdentifier): void
{
$this->cacheActionIdentifiers[] = $cacheActionIdentifier;
}
public function setCacheActionIdentifiers(array $cacheActionIdentifiers): void
{
$this->cacheActionIdentifiers = $cacheActionIdentifiers;
}
public function getCacheActionIdentifiers(): array
{
return $this->cacheActionIdentifiers;
}
}
......@@ -15,6 +15,8 @@
namespace TYPO3\CMS\Backend\Backend\ToolbarItems;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Backend\Backend\Event\ModifyClearCacheActionsEvent;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Toolbar\ClearCacheActionsHookInterface;
use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
......@@ -79,7 +81,15 @@ class ClearCacheToolbarItem implements ToolbarItemInterface
$this->optionValues[] = 'all';
}
if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'])) {
trigger_error(
'The hook $TYPO3_CONF_VARS[SC_OPTIONS][additionalBackendItems][cacheActions] is deprecated and will stop working in TYPO3 v12.0. Use the ModifyClearCacheActionsEvent instead.',
E_USER_DEPRECATED
);
}
// Hook for manipulating cacheActions
// @deprecated will be removed in TYPO3 v12.0.
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'] ?? [] as $cacheAction) {
$hookObject = GeneralUtility::makeInstance($cacheAction);
if (!$hookObject instanceof ClearCacheActionsHookInterface) {
......@@ -87,6 +97,11 @@ class ClearCacheToolbarItem implements ToolbarItemInterface
}
$hookObject->manipulateCacheActions($this->cacheActions, $this->optionValues);
}
$event = new ModifyClearCacheActionsEvent($this->cacheActions, $this->optionValues);
$event = GeneralUtility::getContainer()->get(EventDispatcherInterface::class)->dispatch($event);
$this->cacheActions = $event->getCacheActions();
$this->optionValues = $event->getCacheActionIdentifiers();
}
/**
......
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Toolbar;
/**
* Interface for classes which hook into \TYPO3\CMS\Backend\Toolbar\ClearCacheToolbarItem and manipulate CacheMenuItems array
* @deprecated since TYPO3 v11 LTS, will be removed in TYPO3 v12.0. Use the PSR-14-based ModifyClearCacheActionsEvent instead.
*/
interface ClearCacheActionsHookInterface
{
......
.. include:: ../../Includes.txt
=======================================================
Deprecation: #95083 - Backend toolbar CacheActions hook
=======================================================
See :issue:`95083`
Description
===========
The TYPO3 Hook :php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions']`
which can be used to modify the cache actions, shown in the TYPO3 Backend
top toolbar, has been deprecated.
The accompanied PHP Interface for the hook
:php:`TYPO3\CMS\Backend\Toolbar\ClearCacheActionsHookInterface` has been
marked as deprecated as well.
Impact
======
If the hook is registered in a TYPO3 installation, a PHP deprecation
message is triggered. The extension scanner also detects any usage
of the deprecated interface as strong, and the definition of the
hook as weak match.
Affected Installations
======================
TYPO3 installations with custom extensions using this hook.
Migration
=========
Migrate to the newly introduced `ModifyClearCacheActionsEvent` PSR-14 event.
.. index:: PHP-API, FullyScanned, ext:backend
.. include:: ../../Includes.txt
=========================================================
Feature: #95083 - New PSR-14 ModifyClearCacheActionsEvent
=========================================================
See :issue:`95083`
Description
===========
A new PSR-14 event `ModifyClearCacheActionsEvent` has been added to
TYPO3 Core. This event is fired in the :php:`ClearCacheToolbarItem`
class and allows extensions to modify the clear cache actions, shown
in the TYPO3 Backend top toolbar.
The event can be used to change or remove exisiting clear cache
actions, as well as to add new actions. Therefore the event also
contains, next to the usual "getter" and "setter", the convenience
method :php:`add` for the :php:`cacheActions` and
:php:`cacheActionIdentifiers` arrays.
Registration of the Event in your extensions' `Services.yaml`:
.. code-block:: yaml
MyVendor\MyPackage\Toolbar\MyEventListener:
tags:
- name: event.listener
identifier: 'my-package/toolbar/my-event-listener'
The corresponding event listener class:
.. code-block:: php
use TYPO3\CMS\Backend\Backend\Event\ModifyClearCacheActionsEvent;
class MyEventListener {
public function __invoke(ModifyClearCacheActionsEvent $event): void
{
// do magic here
}
}
Impact
======
This event can be used to modify the clear cache actions, shown in the
TYPO3 Backend top toolbar.
.. index:: PHP-API, ext:backend
......@@ -517,4 +517,9 @@ return [
'Deprecation-95089-ExtendedFileUtilityProcessDataHook.rst',
],
],
'$GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'additionalBackendItems\'][\'cacheActions\']' => [
'restFiles' => [
'Deprecation-95083-BackendToolbarCacheActionsHook.rst',
],
],
];
......@@ -1804,4 +1804,9 @@ return [
'Deprecation-95089-ExtendedFileUtilityProcessDataHook.rst',
],
],
'TYPO3\CMS\Backend\Toolbar\ClearCacheActionsHookInterface' => [
'restFiles' => [
'Deprecation-95083-BackendToolbarCacheActionsHook.rst',
],
],
];
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment