ModifyDatabaseQueryForRecordListingEvent

New in version 12.0

This event has been introduced to replace the following removed hooks:

  • $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable']
  • $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['modifyQuery']
  • $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['makeSearchStringConstraints']

The PSR-14 event \TYPO3\CMS\Backend\View\Event\ModifyDatabaseQueryForRecordListingEvent allows to alter the query builder SQL statement before a list of records is rendered in record lists, such as the List module or an element browser.

Example

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

declare(strict_types=1);

namespace MyVendor\MyExtension\Backend\EventListener;

use TYPO3\CMS\Backend\View\Event\ModifyDatabaseQueryForRecordListingEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;

#[AsEventListener(
    identifier: 'my-extension/backend/modify-database-query-for-record-list',
)]
final readonly class MyEventListener
{
    public function __invoke(ModifyDatabaseQueryForRecordListingEvent $event): void
    {
        $queryBuilder = $event->getQueryBuilder();

        // ... do something ...

        $event->setQueryBuilder($queryBuilder);
    }
}
Copied!

New in version 13.0

The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, or if you need to be compatible with older TYPO3 versions, you can also register an event listener via the Configuration/Services.yaml file. Switch to an older version of this page for an example or have a look at the section Implementing an event listener in your extension.

API

class \TYPO3\CMS\Backend\View\Event\ ModifyDatabaseQueryForRecordListingEvent

Use this Event to alter the database query when loading content for a page (usually in the list module) before it is executed.

getQueryBuilder ( )
returntype

TYPO3\CMS\Core\Database\Query\QueryBuilder

setQueryBuilder ( TYPO3\\CMS\\Core\\Database\\Query\\QueryBuilder $queryBuilder)
param TYPO3\\CMS\\Core\\Database\\Query\\QueryBuilder $queryBuilder

the queryBuilder

getTable ( )
returntype

string

getPageId ( )
returntype

int

getFields ( )
returntype

array

getFirstResult ( )
returntype

int

getMaxResults ( )
returntype

int

getDatabaseRecordList ( )
returntype

TYPO3\CMS\Backend\RecordList\DatabaseRecordList