Feature: #97450 - PSR-14 event for modifying version differences
See forge#97450
Description
A new PSR-14 event \TYPO3\
has been introduced which serves as a direct replacement for the now removed
$GLOBALS
hook.
It can be used to modify the version differences data, used for the display
in the Workspaces backend module. Those data can be accessed with
the get
method, and updated using
the set
method.
The version differences array
contains the differences of each field,
with the following keys:
field
: The corresponding field name,label
: The corresponding fields' label,content
: The field values difference
Furthermore does the event provide the following methods
get
: Returns the records live data (used to create the version difference)Live Record Data () get
: Returns meta information like current stage and current workspaceParameters ()
Note
The removed hook allowed to update the live record data. This however had no effect since those data are not further used by TYPO3. Therefore, the new event does no longer provide a setter for the live record data.
Note
The removed hook contained an instance of Diff
, which can
be used to generate the differences string
. Since PSR-14 events
are usually pure data objects, without dependencies to any service, the
new PSR-14 event does no longer provide an instance of Diff
.
Listeners have to inject the service on their own - if needed.
Example
Registration of the event in your extension's Services.
:
MyVendor\MyPackage\Workspaces\MyEventListener:
tags:
- name: event.listener
identifier: 'my-package/workspaces/modify-version-differences'
The corresponding event listener class:
use TYPO3\CMS\Core\Utility\DiffUtility;
use TYPO3\CMS\Workspaces\Event\ModifyVersionDifferencesEvent;
final class MyEventListener
{
public function __construct(protected readonly DiffUtility $diffUtility)
{
$this->diffUtility->stripTags = false;
}
public function __invoke(ModifyVersionDifferencesEvent $event): void
{
$differences = $event->getVersionDifferences();
foreach($differences as $key => $difference) {
if ($difference['field'] === 'my_test_field') {
$differences[$key]['content'] = $this->diffUtility->makeDiffDisplay('a', 'b');
}
}
$event->setVersionDifferences($differences);
}
}
Impact
It's now possible to modify the version differences of a versioned record,
using the new PSR-14 event Modify
.