ModifyConstraintsForLiveSearchEvent 

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: Always show marked pages in the live search 

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

declare(strict_types=1);

namespace MyVendor\MyExtension\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 

final 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|\TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression>
addConstraints(string|\TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression ...$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(string|\TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression $constraint)
param $constraint

the constraint

getTableName()
Returns
string
getSearchDemand()
Returns
\TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand