BeforeRecordDownloadIsExecutedEvent

New in version 13.2

This PSR-14 event replaces the $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['customizeCsvHeader'] and $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['customizeCsvRow'], hooks, which have been deprecated with TYPO3 v13.2. See also Migration.

The event TYPO3\CMS\Backend\RecordList\Event\BeforeRecordDownloadIsExecutedEvent can be used to modify the result of a download / export initiated via the Web > List module.

The event lets you change both the main part and the header of the data file. You can use it to edit data to follow GDPR rules, change or translate data, create backups or web hooks, record who accesses the data, and more.

Example: Redact columns with private content in exports

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

declare(strict_types=1);

namespace MyVendor\MyExtension\Backend\EventListener;

use TYPO3\CMS\Backend\RecordList\Event\BeforeRecordDownloadIsExecutedEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;

#[AsEventListener(identifier: 'my-package/record-list-download-data')]
final readonly class DataListener
{
    public function __invoke(BeforeRecordDownloadIsExecutedEvent $event): void
    {
        // List of redactable fields.
        $gdprFields = ['title', 'author'];

        $headerRow = $event->getHeaderRow();
        $records = $event->getRecords();

        // Iterate header to mark redacted fields...
        foreach ($headerRow as $headerRowKey => $headerRowValue) {
            if (in_array($headerRowKey, $gdprFields, true)) {
                $headerRow[$headerRowKey] .= ' (REDACTED)';
            }
        }

        // Redact actual content...
        foreach ($records as $index => $record) {
            foreach ($gdprFields as $gdprField) {
                if (isset($record[$gdprField])) {
                    $records[$index][$gdprField] = '(REDACTED)';
                }
            }
        }

        $event->setHeaderRow($headerRow);
        $event->setRecords($records);
    }
}
Copied!

API of BeforeRecordDownloadIsExecutedEvent

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

Listeners to this event are able to manipulate the download of records, usually triggered via Web > List.

getHeaderRow ( )
Returns
array
setHeaderRow ( array $headerRow)
param $headerRow

the headerRow

getRecords ( )
Returns
array
setRecords ( array $records)
param $records

the records

getRequest ( )
Returns
\Psr\Http\Message\ServerRequestInterface
getTable ( )
Returns
string
getFormat ( )
Returns
string
getFilename ( )
Returns
string
getId ( )
Returns
int
getModTSconfig ( )
Returns
array
getColumnsToRender ( )
Returns
array
isHideTranslations ( )
Returns
bool

Migration

Deprecated since version 13.2

The previously used hooks $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['customizeCsvHeader'] and $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['customizeCsvRow'], used to manipulate the download / export configuration of records, triggered in the Web > List backend module, have been deprecated in favor of a new PSR-14 event TYPO3\CMS\Backend\RecordList\Event\BeforeRecordDownloadIsExecutedEvent.

Migrating customizeCsvHeader

The prior hook parameter/variable fields is now available via $event->getColumnsToRender(). The actual record data (previously $this->recordList, submitted to the hook as its object reference) is accessible via $event->getHeaderRow().

Migrating customizeCsvRow

The following prior hook parameters/variables have these substitutes:

databaseRow
is now available via $event->getRecords() (see note below).
tableName
is now available via $event->getTable().
pageId
is now available via $event->getId().

The actual record data (previously $this->recordList, submitted to the hook as its object reference) is accessible via $event->getRecords().

Please note that the hook was previously executed once per row retrieved from the database. The PSR-14 event however - due to performance reasons - is only executed for the full record list after database retrieval, thus allows post-processing on this whole dataset.