AfterRecordListRowPreparedEvent
New in version 14.2 Feature: #107003 - Add event to change record data in list view
The PSR-14 event
\TYPO3\ is
fired by
\TYPO3\ once a row of
the record list is prepared, just before it is rendered. A listener reads the
rendered cells of the row and the HTML attributes of its
<tr>
element,
and can replace either.
get returns the cells by column name. Writing a key that the
list does not render has no effect, so these are the ones worth changing:
_SELECTOR_- The checkbox of the row.
icon- The record icon.
__label - The title of the record, including its link.
headerholds the same value and is used only while__is unset, so writelabel __.label _CONTROL_- The buttons at the end of the row.
_LOCALIZATION_,_LOCALIZATION_b - The language of the record and the language it is translated from.
rowDescription - The description of the row.
uid- The uid of the record. TYPO3 ignores a change to it.
get returns class, data- and title for the
row element. TYPO3 has already filled them, so add to a value instead of
replacing it, or the state the list shows gets lost.
The event also carries the table name, the record, its title, and its lock
information.
get returns the
Database itself. TYPO3
Core passes this parent object on purpose, because the class still exposes
state that a listener needs. Use as little of it as you can. TYPO3 Core plans
to split the class up, and the method goes with it.
Example: mark a row that somebody else is editing
The following listener marks every record that somebody else is editing. It
adds a class to the row and puts the lock message into the title attribute.
It also appends a marker to the record title:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\EventListener;
use TYPO3\CMS\Backend\RecordList\Event\AfterRecordListRowPreparedEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
final readonly class MarkLockedRecordListRowListener
{
#[AsEventListener('my_extension/mark-locked-record-list-row')]
public function __invoke(AfterRecordListRowPreparedEvent $event): void
{
$lockInfo = $event->getLockInfo();
if (!is_array($lockInfo)) {
// The record is not being edited by anybody else
return;
}
$tagAttributes = $event->getTagAttributes();
// Append, so that the classes TYPO3 set are kept
$tagAttributes['class'] = trim(
($tagAttributes['class'] ?? '') . ' my-extension-locked',
);
$tagAttributes['title'] = $lockInfo['msg'] ?? '';
$event->setTagAttributes($tagAttributes);
$data = $event->getData();
$data['__label'] = ($data['__label'] ?? '') . ' (locked)';
$event->setData($data);
}
}