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 insetSearchPageIds()
: Allows to define page ids to search ingetSearchDemand()
: Returns theSearchDemand
, used by the live searchsetSearchDemand()
: Allows to set a customSearchDemand
objectignoreTable()
: Allows to ignore / exclude a table from the lookupsetIgnoredTables()
: Allows to overwrite the ignored tablesisTableIgnored()
: Returns whether a specific table is ignoredgetIgnoredTables()
: 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'
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');
}
}
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.