From a4b3ddf64d1de7fffd27464aec574507481a47f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20B=C3=BClter?= Date: Fri, 25 Oct 2024 10:29:01 +0200 Subject: [PATCH] [BUGFIX] Fix undefined array key "sortByAdmin", closes #252 Additionally, add function setConfigurationDefaults() which acts as a central place to set default values for the configuration. Additionally, throw an exception if the startinpoint is not set. --- ChangeLog | 3 ++- Classes/Lib/Db.php | 19 ++++++++-------- Classes/Lib/PluginBaseHelper.php | 8 ++++++- Classes/Plugins/PluginBase.php | 22 ++++++++++++++----- .../OverrideRecordStoragePage.rst | 15 ++++++++----- 5 files changed, 45 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 874d4ef8d..d42566b03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,8 @@ ChangeLog Upcoming version -[BUGFIX] Add missing storage page an recursive option. Thanks to Torben Hansen. https://github.com/tpwd/ke_search/issues/251 +[BUGFIX] Add missing storage page and recursive option. Thanks to Torben Hansen. https://github.com/tpwd/ke_search/issues/251 +[BUGFIX] Undefined array key "sortByAdmin". Thanks to Simon Praetorius. https://github.com/tpwd/ke_search/issues/252 Version 6.0.0, 18 October 2024 [!!!] This version drops support for TYPO3 11. diff --git a/Classes/Lib/Db.php b/Classes/Lib/Db.php index 1d974019d..0c56db106 100644 --- a/Classes/Lib/Db.php +++ b/Classes/Lib/Db.php @@ -573,26 +573,27 @@ public function createQueryForDateRange() */ public function getOrdering() { - // if the following code fails, fall back to this default ordering - $orderBy = $this->conf['sortWithoutSearchword'] ?? 'sortdate desc'; + // If the following code fails, fall back to this default ordering + $orderBy = $this->conf['sortWithoutSearchword']; - // if sorting in FE is allowed + // If sorting in FE is allowed if ($this->conf['showSortInFrontend'] ?? false) { $piVarsField = $this->pObj->piVars['sortByField'] ?? ''; $piVarsDir = $this->pObj->piVars['sortByDir'] ?? ''; $piVarsDir = ($piVarsDir == '') ? 'asc' : $piVarsDir; - if (!empty($piVarsField)) { // if an ordering field is defined by GET/POST + + // Check if an ordering field is defined by GET/POST and use that. + // If sortByVisitor is not set OR not in the list of + // allowed fields then use fallback ordering in "sortWithoutSearchword" + if (!empty($piVarsField)) { $isInList = GeneralUtility::inList($this->conf['sortByVisitor'], $piVarsField); if ($this->conf['sortByVisitor'] != '' && $isInList) { $orderBy = $piVarsField . ' ' . $piVarsDir; } - // if sortByVisitor is not set OR not in the list of - // allowed fields then use fallback ordering in "sortWithoutSearchword" } } else { - // if sortByVisitor is not set OR not in the list of - // allowed fields then use fallback ordering in "sortWithoutSearchword" - if (!empty($this->pObj->wordsAgainst)) { // if sorting is predefined by admin + // If sorting is predefined by admin + if (!empty($this->pObj->wordsAgainst)) { $orderBy = $this->conf['sortByAdmin']; } } diff --git a/Classes/Lib/PluginBaseHelper.php b/Classes/Lib/PluginBaseHelper.php index bc6a5cd60..53751d21b 100644 --- a/Classes/Lib/PluginBaseHelper.php +++ b/Classes/Lib/PluginBaseHelper.php @@ -82,7 +82,13 @@ public function getStartingPoint(): string // @extensionScannerIgnoreLine $startingpoint['pages'] = $this->pObj->conf['overrideStartingPoint']; // @extensionScannerIgnoreLine - $startingpoint['recursive'] = $this->pObj->conf['overrideStartingPointRecursive']; + $startingpoint['recursive'] = $this->pObj->conf['overrideStartingPointRecursive'] ?? 0; + } + + if (empty($startingpoint['pages'])) { + throw new \Exception('No starting point found. Please set the starting point in the plugin' + . ' configuration or via TypoScript: ' + . 'https://docs.typo3.org/p/tpwd/ke_search/main/en-us/Configuration/OverrideRecordStoragePage.html.'); } return $this->pObj->pi_getPidList($startingpoint['pages'], $startingpoint['recursive']); diff --git a/Classes/Plugins/PluginBase.php b/Classes/Plugins/PluginBase.php index 582c86392..549e7ec64 100644 --- a/Classes/Plugins/PluginBase.php +++ b/Classes/Plugins/PluginBase.php @@ -189,9 +189,10 @@ public function init(ServerRequestInterface $request) // make settings from FlexForm available in general configuration ($this->conf) $this->moveFlexFormDataToConf($flexFormConfiguration); + $this->setConfigurationDefaults(); - // explode flattened piVars to multi-dimensional array and clean them - $additionalAllowedPiVars = $this->conf['additionalAllowedPiVars'] ?? ''; + // explode flattened piVars to multidimensional array and clean them + $additionalAllowedPiVars = $this->conf['additionalAllowedPiVars']; $this->piVars = SearchHelper::explodePiVars($this->piVars, $additionalAllowedPiVars); $this->piVars = $this->div->cleanPiVars($this->piVars, $additionalAllowedPiVars); @@ -286,16 +287,16 @@ public function init(ServerRequestInterface $request) $this->piVars['sortByDir'] = 'desc'; } - // after the searchword is removed, sorting for "score" is not possible + // After the searchword is removed, sorting for "score" is not possible // anymore. So remove this sorting here and put it back to default. if (!$this->sword && ($this->piVars['sortByField'] ?? '') == 'score') { unset($this->piVars['sortByField']); unset($this->piVars['sortByDir']); } - // perform search at this point already if we need to calculate what + // Perform search at this point already if we need to calculate what // filters to display. - if (isset($this->conf['checkFilterCondition']) && $this->conf['checkFilterCondition'] != 'none' && !$this->allowEmptySearch()) { + if ($this->conf['checkFilterCondition'] != 'none' && !$this->allowEmptySearch()) { $this->db->getSearchResults(); } @@ -311,6 +312,17 @@ public function init(ServerRequestInterface $request) } } + protected function setConfigurationDefaults(): void + { + $this->conf['resultsPerPage'] = $this->conf['resultsPerPage'] ?? 10; + $this->conf['resultLinkTargetFiles'] = $this->conf['resultLinkTargetFiles'] ?? '_blank'; + $this->conf['resultLinkTarget'] = $this->conf['resultLinkTarget'] ?? ''; + $this->conf['additionalAllowedPiVars'] = $this->conf['additionalAllowedPiVars'] ?? ''; + $this->conf['sortByAdmin'] = $this->conf['sortByAdmin'] ?? 'score desc'; + $this->conf['sortWithoutSearchword'] = $this->conf['sortWithoutSearchword'] ?? 'sortdate desc'; + $this->conf['checkFilterCondition'] = $this->conf['checkFilterCondition'] ?? 'multi'; + } + /** * Move all FlexForm data of current record to conf array ($this->conf) * diff --git a/Documentation/Configuration/OverrideRecordStoragePage.rst b/Documentation/Configuration/OverrideRecordStoragePage.rst index cde5ac0c9..cf50e21e8 100755 --- a/Documentation/Configuration/OverrideRecordStoragePage.rst +++ b/Documentation/Configuration/OverrideRecordStoragePage.rst @@ -2,14 +2,17 @@ .. _configuration-override-record-storage-page: -============================ -Override record storage page -============================ +============================================ +Override record storage page (Startingpoint) +============================================ -It is possible to override the record storage page defined in the plugin using TypoScript. This is useful -if you want to serve different search results depending on TypoScript conditions. +It is possible to override the record storage page (or "Startingpoint") defined +in the plugin using TypoScript. This is useful if you want to serve different +search results depending on TypoScript conditions or if you include the plugin +via TypoScript. -For example you could serve different search results to logged in users. +For example you could serve different search results to logged in users by +setting the override record storage page to a different page id. Setup TypoScript: