ModifyDatabaseQueryForContentEvent
New in version 12.0
This event has been introduced which serves as a drop-in replacement for the removed
$GLOBALS
hook.
Use the PSR-14 event \TYPO3\
to filter out certain content elements from being shown in the
Page module.
Example
Registration of the event in your extension's Services.
:
services:
# Place here the default dependency injection configuration
MyVendor\MyExtension\Backend\EventListener\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/backend/modify-database-query-for-content'
Read how to configure dependency injection in extensions.
The corresponding event listener class:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Backend\EventListener;
use TYPO3\CMS\Backend\View\Event\ModifyDatabaseQueryForContentEvent;
use TYPO3\CMS\Core\Database\Connection;
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);
}
}
API
- class ModifyDatabaseQueryForContentEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Backend\ View\ Event\ Modify Database Query For Content Event
Use this Event to alter the database query when loading content for a page.