[FEATURE] Add constraint hook in DatabaseRecordList->makeSearchString 90/48090/9
authorTomita Militaru <militarutomita@gmail.com>
Wed, 11 May 2016 21:33:29 +0000 (23:33 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 8 Feb 2018 23:31:18 +0000 (00:31 +0100)
A newly introduced hook in DatabaseRecordList->makeSearchString allows to
modify the constraints which are applied to the search string.

Resolves: #71911
Releases: master
Change-Id: I7513ce9c17a9dfef76caa4e78a61f8efed21d540
Reviewed-on: https://review.typo3.org/48090
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Documentation/Changelog/master/Feature-71911-AddConstraintHookInDatabaseRecordListMakeSearchString.rst [new file with mode: 0644]
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-71911-AddConstraintHookInDatabaseRecordListMakeSearchString.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-71911-AddConstraintHookInDatabaseRecordListMakeSearchString.rst
new file mode 100644 (file)
index 0000000..ded9ac6
--- /dev/null
@@ -0,0 +1,47 @@
+.. include:: ../../Includes.txt
+
+==============================================================================
+Feature: #71911 - Add constraint hook in  DatabaseRecordList->makeSearchString
+==============================================================================
+
+See :issue:`71911`
+
+Description
+===========
+
+A newly introduced hook in DatabaseRecordList->makeSearchString allows to
+modify the constraints which are applied to the search string.
+
+Example
+=======
+
+An example implementation could look like this:
+
+:file:`EXT:my_site/ext_localconf.php`
+
+.. code-block:: php
+
+   $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList::class]['makeSearchStringConstraints'][1313131313] =
+      \MyVendor\MySite\Hooks\DatabaseRecordListHook::class . '->makeSearchStringConstraints';
+
+
+:file:`EXT:my_site/Classes/Hooks/DatabaseRecordListHook.php`
+
+.. code-block:: php
+
+   namespace MyVendor\MySite\Hooks;
+
+   class DatabaseRecordListHook
+   {
+      public function makeSearchStringConstraints(
+         \TYPO3\CMS\Core\Database\Query\QueryBuilder $queryBuilder
+         array $constraints,
+         string $searchString,
+         string $table,
+         int $currentPid,
+      ) {
+         return $constraints;
+      }
+   }
+
+.. index:: Backend, Database, PHP-API
\ No newline at end of file
index ee2bca6..4b41206 100644 (file)
@@ -3450,6 +3450,19 @@ class DatabaseRecordList
                 }
             }
         }
+        // Call hook to add or change the list
+        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][DatabaseRecordList::class]['makeSearchStringConstraints'] ?? [] as $className) {
+            $hookObject = GeneralUtility::makeInstance($className);
+            if (method_exists($hookObject, 'makeSearchStringConstraints')) {
+                $constraints = $hookObject->makeSearchStringConstraints(
+                    $queryBuilder,
+                    $constraints,
+                    $this->searchString,
+                    $table,
+                    $currentPid
+                );
+            }
+        }
         // If no search field conditions have been built ensure no results are returned
         if (empty($constraints)) {
             return '0=1';