Skip to content

Commit

Permalink
Allow to leave preset filter values empty
Browse files Browse the repository at this point in the history
We fixed the bug that one could not filter for empty string, yet we
removed the possibility to not define a preset at all by doing so.
This restores the possibility by allowing "null" as value.
  • Loading branch information
discordier committed Jul 3, 2024
1 parent e0a46b4 commit e83265a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,12 @@ protected function buildFilterParamsFor(DC_Table $dataContainer, $elementName)
return;
}

$translatedNull = $this->translator->trans('filter_option.null', [], self::$tableName);

$collection = $this->filterFactory->createCollection($filterId);
$dca = $collection->getParameterDCA();
foreach ($dca as $fieldName => $subField) {
$options = [];
$options = ['--null--' => $translatedNull];
foreach (($subField['options'] ?? []) as $key => $value) {
$newKey = $this->loadCallback($key);
if (null !== $newKey) {
Expand All @@ -416,7 +418,7 @@ protected function buildFilterParamsFor(DC_Table $dataContainer, $elementName)
*/
public function saveCallback(string $value = null)
{
return null === $value ? null : base64_decode($value);
return null === $value ? '--null--' : base64_decode($value);
}

/**
Expand All @@ -428,7 +430,7 @@ public function saveCallback(string $value = null)
*/
public function loadCallback(string $value = null)
{
return null === $value ? null : trim(base64_encode($value), '=');
return null === $value ? '--null--' : trim(base64_encode($value), '=');
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/CoreBundle/Resources/translations/tl_content.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<trans-unit id="editfiltersetting.description" resname="editfiltersetting.description">
<source>Edit the filter setting ID %id%.</source>
</trans-unit>
<trans-unit id="filter_option.null" resname="filter_option.null">
<source>- no value [null] -</source>
</trans-unit>
</body>
</file>
</xliff>
3 changes: 3 additions & 0 deletions src/CoreBundle/Resources/translations/tl_modules.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<trans-unit id="editfiltersetting.description" resname="editfiltersetting.description">
<source>Edit the filter setting ID %id%.</source>
</trans-unit>
<trans-unit id="filter_option.null" resname="filter_option.null">
<source>- no value [null] -</source>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit e83265a

Please sign in to comment.