ModifyDatabaseQueryForContentEvent

New in version 12.0: This event has been introduced which serves as a drop-in replacement for the removed $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][PageLayoutView::class]['modifyQuery'] hook.

Use the PSR-14 event \TYPO3\CMS\Backend\View\Event\ModifyDatabaseQueryForContentEvent to filter out certain content elements from being shown in the Page module.

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\ModifyDatabaseQueryForContentEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Database\Connection;

#[AsEventListener(
    identifier: 'my-extension/backend/modify-database-query-for-content'
)]
final class MyEventListener
{
    public function __invoke(ModifyDatabaseQueryForContentEvent $event): void
    {
        // Early return if we do not need to react
        if ($event->getTable() !== 'tt_content') {
            return;
        }

        // Retrieve QueryBuilder instance from event
        $queryBuilder = $event->getQueryBuilder();

        // Add an additional condition to the QueryBuilder for the table
        // Note: This is only a example, modify the QueryBuilder instance
        //       here to your needs.
        $queryBuilder = $queryBuilder->andWhere(
            $queryBuilder->expr()->neq(
                'some_field',
                $queryBuilder->createNamedParameter(1, Connection::PARAM_INT)
            )
        );

        // Set updated QueryBuilder to event
        $event->setQueryBuilder($queryBuilder);
    }
}

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\ModifyDatabaseQueryForContentEvent

Use this Event to alter the database query when loading content for a page.

getQueryBuilder()
Return type

TYPO3\CMS\Core\Database\Query\QueryBuilder

setQueryBuilder(TYPO3\\CMS\\Core\\Database\\Query\\QueryBuilder $queryBuilder)
Parameters
  • $queryBuilder (TYPO3\CMS\Core\Database\Query\QueryBuilder) -- the queryBuilder

getTable()
Return type

string

getPageId()
Return type

int