[TASK] Add a hook to customize field list for Backend search
authorDmitry Dulepov <dmitry@typo3.org>
Fri, 14 Oct 2011 09:51:56 +0000 (12:51 +0300)
committerJigal van Hemert <jigal@xs4all.nl>
Sat, 15 Oct 2011 11:44:32 +0000 (13:44 +0200)
Due to Backend search changes, we need a hook to alter table
search configuration in the List module. This hook can be used
by extensions to add their own fields to the list of searchable
fields. Also this hook will be used by a compatibility extension
that provides legacy search functionality until extension
authors update their extensions for smarter search.

Change-Id: I0b37ceb617779925555bcbeb10da9ef093d4bd81
Resolves: #30915
Releases: 4.6
Reviewed-on: http://review.typo3.org/5785
Reviewed-by: Tolleiv Nietsch
Tested-by: Tolleiv Nietsch
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
typo3/class.db_list.inc

index 7d6a3a5..3a8faa9 100644 (file)
@@ -551,9 +551,8 @@ class recordList extends t3lib_recordList {
                        // Make query, only if table is valid and a search string is actually defined:
                if ($this->searchString) {
                        $result = ' AND 0=1';
-                       if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['searchFields']) {
-                               $searchableFields = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['searchFields'], TRUE);
-
+                       $searchableFields = $this->getSearchFields($table);
+                       if (count($searchableFields) > 0) {
                                        // Loading full table description - we need to traverse fields:
                                t3lib_div::loadTCA($table);
 
@@ -613,6 +612,38 @@ class recordList extends t3lib_recordList {
        }
 
        /**
+        * Fetches a list of fields to use in the Backend search for the given table.
+        *
+        * @param string $tableName
+        * @return array
+        */
+       protected function getSearchFields($tableName) {
+               $fieldArray = array();
+               $fieldListWasSet = FALSE;
+
+                       // Get fields from ctrl section of TCA first
+               if (isset($GLOBALS['TCA'][$tableName]['ctrl']['searchFields'])) {
+                       $fieldArray = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$tableName]['ctrl']['searchFields'], TRUE);
+                       $fieldListWasSet = TRUE;
+               }
+
+                       // Call hook to add or change the list
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['mod_list']['getSearchFieldList']))      {
+                       $hookParameters = array(
+                               'tableHasSearchConfiguration' => $fieldListWasSet,
+                               'tableName' => $tableName,
+                               'searchFields' => &$fieldArray,
+                               'searchString' => $this->searchString
+                       );
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['mod_list']['getSearchFieldList'] as $hookFunction)  {
+                               t3lib_div::callUserFunction($hookFunction, $hookParameters, $this);
+                       }
+               }
+
+               return $fieldArray;
+       }
+
+       /**
         * Returns the title (based on $code) of a table ($table) with the proper link around. For headers over tables.
         * The link will cause the display of all extended mode or not for the table.
         *