Skip to content

Commit

Permalink
[BUGFIX] Reestablish manipulation of EXT:indexed_search query (#5135)
Browse files Browse the repository at this point in the history
References: TYPO3-Documentation/Changelog-To-Doc#1087
Releases: main, 13.4

Co-authored-by: lina.wolf <lwolf@w-commerce.de>
  • Loading branch information
github-actions[bot] and linawolf authored Dec 5, 2024
1 parent ae5e1d6 commit eee5190
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.. include:: /Includes.rst.txt
.. index:: Events; BeforeFinalSearchQueryIsExecutedEvent
.. _BeforeFinalSearchQueryIsExecutedEvent:

=====================================
BeforeFinalSearchQueryIsExecutedEvent
=====================================

.. versionadded:: 13.4.2 / 14.0
This event was added as a replacement for the removed hook
`$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['pi1_hooks']`.

The PSR-14 :php:`\TYPO3\CMS\IndexedSearch\Event\BeforeFinalSearchQueryIsExecutedEvent`
has been introduced which allows developers to manipulate the (internal)
:php:`\TYPO3\CMS\Core\Database\Query\QueryBuilder`
instance, just before the query gets executed.

.. important::

The provided query (the :php:`\TYPO3\CMS\Core\Database\Query\QueryBuilder`
instance) is controlled by the
TYPO3 Core and is not considered public API. Therefore, developers using this
event need to keep track of underlying changes by TYPO3. Such changes might
be further performance improvements to the query or changes to the
database schema in general.

.. _BeforeFinalSearchQueryIsExecutedEvent-example:

Example
=======

Changing the host of the current request and setting it as canonical:

.. literalinclude:: _BeforeFinalSearchQueryIsExecutedEvent/_MyEventListener.php
:language: php
:caption: EXT:my_extension/Classes/IndexedSearch/EventListener/MyEventListener.php

.. _BeforeFinalSearchQueryIsExecutedEvent-api:

API
===

.. include:: /CodeSnippets/Events/IndexedSearch/BeforeFinalSearchQueryIsExecutedEvent.rst.txt
18 changes: 18 additions & 0 deletions Documentation/ApiOverview/Events/Events/IndexedSearch/Index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.. include:: /Includes.rst.txt
.. index:: pair: Events; Indexed search
.. _eventlist-indexed-search:

==============
Indexed search
==============

The following list contains :ref:`PSR-14 events <EventDispatcher>`
in :composer:`typo3/cms-indexed-search`.

**Contents:**

.. toctree::
:titlesonly:
:glob:

*
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\IndexedSearch\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\IndexedSearch\Event\BeforeFinalSearchQueryIsExecutedEvent;

final readonly class EventListener
{
#[AsEventListener(identifier: 'manipulate-search-query')]
public function beforeFinalSearchQueryIsExecuted(BeforeFinalSearchQueryIsExecutedEvent $event): void
{
$event->queryBuilder->andWhere(
$event->queryBuilder->expr()->eq('some_column', 'some_value'),
);
}
}
1 change: 1 addition & 0 deletions Documentation/CodeSnippets/Config/Api/Events/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
include ('EventsFrontend.php'),
include ('EventsFrontendLogin.php'),
include ('EventsImpexp.php'),
include ('EventsIndexedSearch.php'),
include ('EventsInfo.php'),
include ('EventsInstall.php'),
include ('EventsLinkvalidator.php'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
[
'action' => 'createPhpClassDocs',
'class' => \TYPO3\CMS\IndexedSearch\Event\BeforeFinalSearchQueryIsExecutedEvent::class,
'targetFileName' => 'CodeSnippets/Events/IndexedSearch/BeforeFinalSearchQueryIsExecutedEvent.rst.txt',
'withCode' => false,
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. Generated by https://github.com/TYPO3-Documentation/t3docs-codesnippets
.. php:namespace:: TYPO3\CMS\IndexedSearch\Event
.. php:class:: BeforeFinalSearchQueryIsExecutedEvent
Listeners are able to manipulate the QueryBuilder before the search query gets executed

.. php:attr:: queryBuilder
:public:

.. php:attr:: searchWords
:readonly:
:public:

.. php:attr:: freeIndexUid
:readonly:
:public:

0 comments on commit eee5190

Please sign in to comment.