BeforeSearchInDatabaseRecordProviderEvent

New in version 12.1.

The TYPO3 backend search (also known as "Live Search") uses the \TYPO3\CMS\Backend\Search\LiveSearch\DatabaseRecordProvider to search for records in database tables, having searchFields configured in TCA.

In some individual cases it may not be desirable to search in a specific table. Therefore, the \TYPO3\CMS\Backend\Search\Event\BeforeSearchInDatabaseRecordProviderEvent event is available, which allows to exclude / ignore such tables by adding them to a deny list. Additionally, the PSR-14 event can be used to restrict the search result on certain page IDs or to modify the search query altogether.

Example

Registration of the event in your extension's Services.yaml:

EXT:my_extension/Configuration/Services.yaml
MyVendor\MyExtension\EventListener\BeforeSearchInDatabaseRecordProviderEventListener:
  tags:
    - name: event.listener
      identifier: 'my-extension/before-search-in-database-record-provider-event-listener'

The corresponding event listener class:

EXT:my_extension/Classes/EventListener/BeforeSearchInDatabaseRecordProviderEventListener.php
use TYPO3\CMS\Backend\Search\Event\BeforeSearchInDatabaseRecordProviderEvent;

final class ModifyEditFileFormDataEventListener
{
    public function __invoke(BeforeSearchInDatabaseRecordProviderEvent $event): void
    {
        $event->ignoreTable('my_custom_table');
    }
}

API

class TYPO3\CMS\Backend\Search\Event\BeforeSearchInDatabaseRecordProviderEvent

PSR-14 event to modify the incoming input about which tables should be searched for within the live search results. This allows adding additional DB tables to be excluded / ignored, to further limit the search result on certain page IDs or to modify the search query altogether.

getSearchPageIds()
Return type

array

setSearchPageIds(array $searchPageIds)
Parameters
  • $searchPageIds (array) -- the searchPageIds

getSearchDemand()
Return type

TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand

setSearchDemand(TYPO3\\CMS\\Backend\\Search\\LiveSearch\\SearchDemand $searchDemand)
Parameters
  • $searchDemand (TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand) -- the searchDemand

ignoreTable(string $table)
Parameters
  • $table (string) -- the table

setIgnoredTables(array $tables)
Parameters
  • $tables (array) -- the tables

isTableIgnored(string $table)
Parameters
  • $table (string) -- the table

Return type

bool

getIgnoredTables()
Return type

array