Feature: #93494 - New PSR-14 ModifyQueryForLiveSearchEvent
See forge#93494
Description
A new PSR-14 event \TYPO3\
has been added to TYPO3 Core. This event is fired in the
\TYPO3\
class
and allows extensions to modify the Query
instance
before execution.
The event features the following methods:
get
: Returns the currentQuery Builder () Query
instanceBuilder get
: Returns the table, for which the query will be executedTable Name ()
Registration of the event in your extension's Services.
:
MyVendor\MyPackage\EventListener\ModifyQueryForLiveSearchEventListener:
tags:
- name: event.listener
identifier: 'my-package/modify-query-for-live-search-event-listener'
Copied!
The corresponding event listener class:
use TYPO3\CMS\Backend\Search\Event\ModifyQueryForLiveSearchEvent;
final class ModifyQueryForLiveSearchEventListener
{
public function __invoke(ModifyQueryForLiveSearchEvent $event): void
{
// Get the current instance
$queryBuilder = $event->getQueryBuilder();
// Change limit depending on the table
if ($event->getTableName() === 'pages') {
$queryBuilder->setMaxResults(2);
}
// Reset the orderBy part
$queryBuilder->resetQueryPart('orderBy');
}
}
Copied!
Impact
It is now possible to use a new PSR-14 event for modifying the live search query. This can be used, for example, to adjust the limit for a specific table or to change the result order.