ModifyVersionDifferencesEvent

New in version 12.0

This PSR-14 event replaces the $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['modifyDifferenceArray'] hook.

The PSR-14 event \TYPO3\CMS\Workspaces\Event\ModifyVersionDifferencesEvent can be used to modify the version differences data, used for the display in the Web > Workspaces backend module. Those data can be accessed with the getVersionDifferences() method and updated using the setVersionDifferences(array $versionDifferences) method.

Example

EXT:my_extension/Classes/Workspaces/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Workspaces\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Utility\DiffUtility;
use TYPO3\CMS\Workspaces\Event\ModifyVersionDifferencesEvent;

#[AsEventListener(
    identifier: 'my-extension/modify-version-differences',
)]
final readonly class MyEventListener
{
    public function __construct(private 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!

New in version 13.0

The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, or if you need to be compatible with older TYPO3 versions, you can also register an event listener via the Configuration/Services.yaml file. Switch to an older version of this page for an example or have a look at the section Implementing an event listener in your extension.

API

class \TYPO3\CMS\Workspaces\Event\ ModifyVersionDifferencesEvent

Listeners to this event will be able to modify the differences of versioned records

getVersionDifferences ( )

Get the version differences.

This array contains the differences of each field with the following keys:

  • field: The corresponding field name
  • label: The corresponding field label
  • content: The field values difference
returntype

array

Returns:

list<array{field: string, label: string, content: string}>

setVersionDifferences ( array $versionDifferences)

Modifies the version differences data

param array $versionDifferences

the versionDifferences

getLiveRecordData ( )

Returns the records live data (used to create the version difference)

returntype

array

Returns:

list<array{field: string, label: string, content: string}>

getParameters ( )

Returns meta information like current stage and current workspace

returntype

stdClass