Feature: #99033 - Add table filter for backend search 

See forge#99033

Description 

The TYPO3 backend search (aka "Live Search") is using 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 desired to search in a certain table. Therefore, the new event \TYPO3\CMS\Backend\Search\Event\BeforeSearchInDatabaseRecordProviderEvent has been introduced, which allows to exclude / ignore such tables by adding them to a deny list. Additionally, the new PSR-14 event can be used to further limit the search result on certain page IDs or to modify the search query altogether.

The event features the following methods:

  • getSearchPageIds() : Returns the page ids to search in
  • setSearchPageIds() : Allows to define page ids to search in
  • getSearchDemand() : Returns the SearchDemand , used by the live search
  • setSearchDemand() : Allows to set a custom SearchDemand object
  • ignoreTable() : Allows to ignore / exclude a table from the lookup
  • setIgnoredTables() : Allows to overwrite the ignored tables
  • isTableIgnored() : Returns whether a specific table is ignored
  • getIgnoredTables() : Returns all tables to be ignored from the lookup

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

MyVendor\MyPackage\EventListener\BeforeSearchInDatabaseRecordProviderEventListener:
  tags:
    - name: event.listener
      identifier: 'my-package/before-search-in-database-record-provider-event-listener'
Copied!

The corresponding event listener class:

use TYPO3\CMS\Backend\Search\Event\BeforeSearchInDatabaseRecordProviderEvent;

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

Impact 

It is now possible to ignore specific tables from the backend search using the new PSR-14 event BeforeSearchInDatabaseRecordProviderEvent . The event also allows to adjust the page IDs to search in as well as to modify the corresponding SearchDemand object.