Skip to content

Commit

Permalink
[BUGFIX] ->isFilterSet() should not return true when filter is build …
Browse files Browse the repository at this point in the history
…with a timePeriod in constructor

Because we stumbled of shortener list view where "clear filter" button was always shown even if there was no filter given. Because before this commit, every timePeriod different to default triggers the isSet() (because isFilterSet() was true), no matter if the value was given via POST param (filter) or from constructor. Now we make a difference between constructor and setter value.
For whatever reason extbase property mapper uses constructor injection in FilterDto if the variable has the same name as a property. To prevent this, because we need to use the setter setTimePeriodDefault(), we need a different variable name for the first parameter in the constructor now.
  • Loading branch information
einpraegsam committed Mar 1, 2024
1 parent 66802e9 commit 51e0129
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function initializeAction()
* Always set a default FilterDto even if there are no filter params. In addition, remove categoryScoring with 0 to
* avoid propertymapping exceptions
*
* @param int $timePeriod
* @param int $timePeriod if anything else then default (0) is given, $filter->isPeriodSet() will be true
* @return void
* @throws NoSuchArgumentException
*/
Expand All @@ -149,7 +149,7 @@ protected function setFilter(int $timePeriod = FilterDto::PERIOD_DEFAULT): void
if ($this->request->hasArgument('filter') === false) {
$filter = BackendUtility::getFilterArrayFromSession($this->getActionName(), $this->getControllerName());
if ($filter === []) {
$filter['timePeriod'] = $timePeriod;
$filter['timePeriodDefault'] = $timePeriod;
}
} else {
$filter = (array)$this->request->getArgument('filter');
Expand Down
27 changes: 24 additions & 3 deletions Classes/Domain/Model/Transfer/FilterDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class FilterDto

protected int $limit = 0;
protected int $scoring = 0;

/**
* Needed to compare with timePeriod to check if given from filter or by default
* @var int
*/
protected int $timePeriodDefault = self::PERIOD_DEFAULT;
protected int $timePeriod = self::PERIOD_DEFAULT;
protected int $identified = self::IDENTIFIED_ALL;

Expand Down Expand Up @@ -87,9 +93,12 @@ class FilterDto
protected ?Visitor $visitor = null;
protected ?Company $company = null;

public function __construct(int $timePeriod = self::PERIOD_DEFAULT)
/**
* @param int $timePeriodValue Must be a different variable name then "timePeriod" or "timePeriodDefault"
*/
public function __construct(int $timePeriodValue = self::PERIOD_DEFAULT)
{
$this->setTimePeriod($timePeriod);
$this->setTimePeriodDefault($timePeriodValue);
}

public function getSearchterm(): string
Expand Down Expand Up @@ -232,7 +241,7 @@ public function getTimePeriod(): int

public function isTimePeriodSet(): bool
{
return $this->timePeriod !== self::PERIOD_DEFAULT;
return $this->timePeriod !== $this->timePeriodDefault;
}

public function setTimePeriod(int $timePeriod): self
Expand All @@ -241,6 +250,18 @@ public function setTimePeriod(int $timePeriod): self
return $this;
}

public function getTimePeriodDefault(): int
{
return $this->timePeriodDefault;
}

public function setTimePeriodDefault(int $timePeriodDefault): self
{
$this->timePeriodDefault = $timePeriodDefault;
$this->timePeriod = $timePeriodDefault;
return $this;
}

public function getIdentified(): int
{
return $this->identified;
Expand Down

0 comments on commit 51e0129

Please sign in to comment.