Feature: #97450 - PSR-14 event for modifying version differences

See forge#97450

Description

A new PSR-14 event \TYPO3\CMS\Workspaces\Event\ModifyVersionDifferencesEvent has been introduced which serves as a direct replacement for the now removed $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['modifyDifferenceArray'] 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 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

Furthermore does the event provide 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

Example

Registration of the event in your extension's Services.yaml:

MyVendor\MyPackage\Workspaces\MyEventListener:
  tags:
    - name: event.listener
      identifier: 'my-package/workspaces/modify-version-differences'
Copied!

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);
    }
}
Copied!

Impact

It's now possible to modify the version differences of a versioned record, using the new PSR-14 event ModifyVersionDifferencesEvent.