Feature: #93494 - New PSR-14 ModifyQueryForLiveSearchEvent¶
See forge#93494
Description¶
A new PSR-14 event \TYPO3\CMS\Backend\Search\Event\ModifyQueryForLiveSearchEvent
has been added to TYPO3 Core. This event is fired in the
\TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch
class
and allows extensions to modify the QueryBuilder
instance
before execution.
The event features the following methods:
getQueryBuilder()
: Returns the currentQueryBuilder
instancegetTableName()
: Returns the table, for which the query will be executed
Registration of the event in your extension's Services.yaml
:
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.