AfterRecordListRowPreparedEvent 

The PSR-14 event \TYPO3\CMS\Backend\RecordList\Event\AfterRecordListRowPreparedEvent is fired by \TYPO3\CMS\Backend\RecordList\DatabaseRecordList 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.

getData() 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. header holds the same value and is used only while __label is unset, so write __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.

getTagAttributes() returns class, data-table 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. getRecordList() returns the DatabaseRecordList 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:

EXT:my_extension/Classes/EventListener/MarkLockedRecordListRowListener.php
<?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);
  }
}
Copied!

API 

final class AfterRecordListRowPreparedEvent
Fully qualified name
\TYPO3\CMS\Backend\RecordList\Event\AfterRecordListRowPreparedEvent

An event to modify the record data for a table in the RecordList.

getTable()
Returns
string
getRecord()
Returns
\TYPO3\CMS\Core\Domain\RecordInterface
getData()
Returns
array
setData(array $data)
param $data

the data

getRecTitle()
Returns
?string
getLockInfo()
Returns
bool|array
getRecordList()
Returns
\TYPO3\CMS\Backend\RecordList\DatabaseRecordList
getTagAttributes()
Returns
array
setTagAttributes(array $tagAttributes)
param $tagAttributes

the tagAttributes