ModifyConstraintsForLiveSearchEvent 

New in version 14.2

The PSR-14 event ModifyConstraintsForLiveSearchEvent is fired in the \TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch class and allows search constraints to be added or removed before a search is executed.

This event allows extensions to modify the CompositeExpression OR-combined constraints by adding or removing constraints from an array. This event was necessary because the main query modifĂ­cation event \TYPO3\CMS\Backend\Search\Event\ModifyQueryForLiveSearchEvent cannot access query constraints.

Example 

EXT:my_extension/Classes/Backend/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyPackage\Backend\Search\EventListener;

use TYPO3\CMS\Backend\Search\Event\ModifyConstraintsForLiveSearchEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Database\ConnectionPool;

final readonly class MyEventListener
{
    public function __construct(private ConnectionPool $connectionPool) {}

    #[AsEventListener('my-package/livesearch-enhanced')]
    public function __invoke(ModifyConstraintsForLiveSearchEvent $event): void
    {
        if ($event->getTableName() !== 'pages') {
            return;
        }

        $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
        // Add a constraint so that pages marked with "show_in_all_results=1"
        // will always be shown.
        $constraints[] = $queryBuilder->expr()->eq(
            'show_in_all_results',
            1,
        );

        $event->addConstraints(...$constraints);
    }
}
Copied!

API 

class ModifyConstraintsForLiveSearchEvent
Fully qualified name
\TYPO3\CMS\Backend\Search\Event\ModifyConstraintsForLiveSearchEvent

PSR-14 event to modify the query builder instance for the live search

getConstraints ( )
Returns
array<int,string|CompositeExpression>
addConstraints ( TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression|string ...$constraints)

Note that we only add a single/multiple constraints and do not allow to remove or override existing ones. This is a safeguard to not overwrite security-related query constraints.

param $constraints

the constraints

addConstraint ( TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression|string $constraint)
param $constraint

the constraint

getTableName ( )
Returns
string
getSearchDemand ( )
Returns
TYPO3CMSBackendSearchLiveSearchSearchDemandSearchDemand