BeforeRecordDownloadPresetsAreDisplayedEvent

New in version 13.2

The event \TYPO3\CMS\Backend\RecordList\Event\BeforeRecordDownloadPresetsAreDisplayedEvent can be used to manipulate the list of available download presets in the Web > List module.

See mod.web_list.downloadPresets on how to configure download presets.

Note that the event is dispatched for one specific database table name. If an event listener is created to attach presets to different tables, the listener method must check for the table name, as shown in the example below.

If no download presets exist for a given table, the PSR-14 event can still be used to modify and add presets to it via the setPresets() method.

The array passed from getPresets() to setPresets() can contain an array collection of TYPO3CMSBackendRecordListDownloadPreset objects with the array key using the preset label.

The event listener can also remove array indexes, or also columns of existing array entries by passing a newly constructed DownloadPreset object with the changed label and columns constructor properties.

Example: Manipulate download presets

EXT:my_extension/Classes/Backend/EventListener/DataListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\RecordList\EventListener;

use TYPO3\CMS\Backend\RecordList\DownloadPreset;
use TYPO3\CMS\Backend\RecordList\Event\BeforeRecordDownloadPresetsAreDisplayedEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;

#[AsEventListener(identifier: 'my-extension/modify-record-list-preset')]
final readonly class PresetListener
{
    public function __invoke(BeforeRecordDownloadPresetsAreDisplayedEvent $event): void
    {
        $presets = $event->getPresets();

        $newPresets = match ($event->getDatabaseTable()) {
            'be_users' => [new DownloadPreset('PSR-14 preset', ['uid', 'email'])],
            'pages' => [
                new DownloadPreset('PSR-14 preset', ['title']),
                new DownloadPreset('Another PSR-14 preset', ['title', 'doktype']),
            ],
            'tx_myvendor_myextension' => [new DownloadPreset('PSR-14 preset', ['uid', 'something'])],
        };

        foreach ($newPresets as $newPreset) {
            $presets[] = $newPreset;
        }

        $presets[] = new DownloadPreset('Available everywhere, simple UID list', ['uid']);
        $presets['some-identifier'] = new DownloadPreset('Overwrite preset', ['uid', 'pid'], 'some-identifier');

        $event->setPresets($presets);
    }
}
Copied!

API of BeforeRecordDownloadPresetsAreDisplayedEvent

class BeforeRecordDownloadPresetsAreDisplayedEvent
Fully qualified name
\TYPO3\CMS\Backend\RecordList\Event\BeforeRecordDownloadPresetsAreDisplayedEvent

Event to manipulate the available list of download presets.

Array $presets contains a list of DownloadPreset objects with their methods: getIdentifier(), getLabel() and getColumns().

The event is always coupled to a specific database table.

getPresets ( )
Returns
\DownloadPreset[]
setPresets ( array $presets)
param $presets

the presets

getDatabaseTable ( )
Returns
string
getRequest ( )
Returns
\Psr\Http\Message\ServerRequestInterface
getId ( )
Returns
int

API of DownloadPreset

class DownloadPreset
Fully qualified name
\TYPO3\CMS\Backend\RecordList\DownloadPreset
getIdentifier ( )
Returns
string
getLabel ( )
Returns
string
getColumns ( )
Returns
array
create ( array $preset)
param $preset

the preset

Returns
self