ModifyVersionDifferencesEvent¶
New in version 12.0: This PSR-14 event replaces the
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['modifyDifferenceArray']
hook.
The event 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 getVersionDifferences()
method and updated using the
setVersionDifferences(array $versionDifferences)
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
In addition, the event provides the following methods:
getLiveRecordData()
: Returns the records live data (used to create the version difference)getParameters()
: Returns meta information like current stage and current workspace
API¶
- class TYPO3\CMS\Workspaces\Event\ModifyVersionDifferencesEvent¶
Listeners to this event will be able to modify the differences of versioned records
- getVersionDifferences()¶
- Return type
array
- setVersionDifferences(array $versionDifferences)¶
- Parameters
$versionDifferences (
array
) -- the versionDifferences
- getLiveRecordData()¶
- Return type
array
- getParameters()¶
- Return type
stdClass
Example¶
Registration of the event listener in the extension's Services.yaml
:
MyVendor\MyExtension\Workspaces\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/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);
}
}