[TASK] Remember search filter in RecordList 08/35408/6
authorFrank Nägler <typo3@naegler.net>
Sun, 14 Dec 2014 12:10:37 +0000 (13:10 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 14 Dec 2014 14:54:40 +0000 (15:54 +0100)
In some cases the searchfilter get lost. The patch
enable storing the search term in BE user session.

Resolves: #33627
Releases: master
Change-Id: I2fcf38174c62874252cf76a4c3251da59bd0048a
Reviewed-on: http://review.typo3.org/35408
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/recordlist/Classes/RecordList.php
typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php

index 7a63f02..99a4910 100644 (file)
@@ -179,20 +179,32 @@ class RecordList {
         */
        public function init() {
                $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
+               // Get session data
+               $sessionData = $GLOBALS['BE_USER']->getSessionData(\TYPO3\CMS\Recordlist\RecordList::class);
+               $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
                // GPvars:
                $this->id = (int)GeneralUtility::_GP('id');
                $this->pointer = GeneralUtility::_GP('pointer');
                $this->imagemode = GeneralUtility::_GP('imagemode');
                $this->table = GeneralUtility::_GP('table');
-               $this->search_field = GeneralUtility::_GP('search_field');
+               if (!empty(GeneralUtility::_GP('search_field'))) {
+                       $this->search_field = GeneralUtility::_GP('search_field');
+                       $sessionData['search_field'] = $this->search_field;
+               }
                $this->search_levels = (int)GeneralUtility::_GP('search_levels');
                $this->showLimit = GeneralUtility::_GP('showLimit');
                $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
                $this->clear_cache = GeneralUtility::_GP('clear_cache');
                $this->cmd = GeneralUtility::_GP('cmd');
                $this->cmd_table = GeneralUtility::_GP('cmd_table');
+               if (!empty(GeneralUtility::_GP('search')) && empty(GeneralUtility::_GP('search_field'))) {
+                       $this->search_field = '';
+                       $sessionData['search_field'] = $this->search_field;
+               }
                // Initialize menu
                $this->menuConfig();
+               // Store session data
+               $GLOBALS['BE_USER']->setAndSaveSessionData(\TYPO3\CMS\Recordlist\RecordList::class, $sessionData);
        }
 
        /**
index 76e1de8..9ecc80b 100644 (file)
@@ -477,7 +477,7 @@ class AbstractDatabaseRecordList extends \TYPO3\CMS\Backend\RecordList\AbstractR
                // Setting form-elements, if applicable:
                $formElements = array('', '');
                if ($formFields) {
-                       $formElements = array('<form action="' . htmlspecialchars($this->listURL('', -1, 'firstElementNumber')) . '" method="post">', '</form>');
+                       $formElements = array('<form action="' . htmlspecialchars($this->listURL('', -1, 'firstElementNumber,search_field')) . '" method="post">', '</form>');
                }
                // Make level selector:
                $opt = array();
@@ -496,7 +496,7 @@ class AbstractDatabaseRecordList extends \TYPO3\CMS\Backend\RecordList\AbstractR
                                        ' . $lMenu . '
                                        <label for="showLimit">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.label.limit', TRUE) . ': </label>
                                        <input type="number" placeholder="10" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.limit', TRUE) . '" name="showLimit" id="showLimit" value="' . htmlspecialchars(($this->showLimit ? $this->showLimit : '')) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(5) . ' />
-                                       <input type="submit" name="search" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.search', TRUE) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.search', TRUE) . '" />
+                                       <input type="submit" class="btn" name="search" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.search', TRUE) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.search', TRUE) . '" />
                        ' . $formElements[1] . '</div></div>';
                return $content;
        }
@@ -835,7 +835,7 @@ class AbstractDatabaseRecordList extends \TYPO3\CMS\Backend\RecordList\AbstractR
                if ($this->returnUrl) {
                        $urlParameters['returnUrl'] = $this->returnUrl;
                }
-               if ($this->searchString) {
+               if ((!$exclList || !GeneralUtility::inList($exclList, 'search_field')) && $this->searchString) {
                        $urlParameters['search_field'] = $this->searchString;
                }
                if ($this->searchLevels) {