Skip to content

Commit

Permalink
[BUGFIX] Fix undefined array key "sortByAdmin", closes #252
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
christianbltr committed Oct 25, 2024
1 parent b4e058f commit a4b3ddf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
19 changes: 10 additions & 9 deletions Classes/Lib/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
Expand Down
8 changes: 7 additions & 1 deletion Classes/Lib/PluginBaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
22 changes: 17 additions & 5 deletions Classes/Plugins/PluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}

Expand All @@ -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)
*
Expand Down
15 changes: 9 additions & 6 deletions Documentation/Configuration/OverrideRecordStoragePage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit a4b3ddf

Please sign in to comment.