ModifyQueryBeforeFetchingObjectDataEvent
The PSR-14 event
\TYPO3\
is fired before the storage backend is asked for results from a given query.
Example
The example disables the respect storage page flag for the given types (models). This can be helpful if you are using bounded contexts and therefore have multiple repository and model classes. By using an event listener, this setting is centralized and does not to be repeated in each repository class.
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Extbase\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Extbase\Event\Persistence\ModifyQueryBeforeFetchingObjectDataEvent;
#[AsEventListener(
identifier: 'my-extension/disabled-respect-storage-page',
)]
final readonly class DisableRespectStoragePage
{
private const TYPES = [
\MyVendor\MyExtension\Domain\Model\List\MyRecord::class,
\MyVendor\MyExtension\Domain\Model\Show\MyRecord::class,
];
public function __invoke(ModifyQueryBeforeFetchingObjectDataEvent $event): void
{
// Only apply it to the given types (models)
if (! \in_array($event->getQuery()->getType(), self::TYPES, true)) {
return;
}
$querySettings = $event->getQuery()->getQuerySettings();
$querySettings->setRespectStoragePage(false);
}
}
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/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.