BeforeRecordDownloadIsExecutedEvent
New in version 13.2
This PSR-14 event replaces the
$GLOBALS
and
$GLOBALS
,
hooks, which have been deprecated with TYPO3 v13.2. See also
Migration.
The event \TYPO3\
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.
Table of contents
Example: Redact columns with private content in exports
<?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);
}
}
API of BeforeRecordDownloadIsExecutedEvent
Migration
Deprecated since version 13.2
The previously used hooks
$GLOBALS
and
$GLOBALS
,
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\
.
Migrating customizeCsvHeader
The prior hook parameter/variable fields
is now available via
$event->get
. The actual record data
(previously $this->record
, submitted to the hook as its object
reference) is accessible via $event->get
.
Migrating customizeCsvRow
The following prior hook parameters/variables have these substitutes:
database
Row - is now available via
$event->get
(see note below).Records () table
Name - is now available via
$event->get
.Table () page
Id - is now available via
$event->get
.Id ()
The actual record data
(previously $this->record
, submitted to the hook as its object
reference) is accessible via $event->get
.
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.