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
<?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 readonly 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\
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/
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 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.