Skip to content

Commit

Permalink
bugfix in setDefaultFilter - revert from 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
petrparolek authored and paveljanda committed Dec 1, 2020
1 parent e21e1a6 commit b0598bc
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -1367,21 +1367,25 @@ public function setDefaultFilter(array $defaultFilter, bool $useOnReset = true):
{
foreach ($defaultFilter as $key => $value) {
$filter = $this->getFilter($key);

if ($filter instanceof FilterMultiSelect && !is_array($value)) {
if (!$filter) {
throw new DataGridException("Can not set default value to nonexisting filter [$key]");
}
if ($filter instanceof Filter\FilterMultiSelect && !is_array($value)) {
throw new DataGridException(
sprintf('Default value of filter [%s] - MultiSelect has to be an array', $key)
"Default value of filter [$key] - MultiSelect has to be an array"
);
}

if ($filter instanceof FilterRange || $filter instanceof FilterDateRange) {
if (!is_array($value) || !isset($value['from'], $value['to'])) {
if ($filter instanceof Filter\FilterRange || $filter instanceof Filter\FilterDateRange) {
if (!is_array($value)) {
throw new DataGridException(
"Default value of filter [$key] - Range/DateRange has to be an array [from/to => ...]"
);
}
$temp = $value;
unset($temp['from'], $temp['to']);
if (!empty($temp)) {
throw new DataGridException(
sprintf(
'Default value of filter [%s] - %s has to be an array [from/to => ...]',
FilterDateRange::class,
$key
)
"Default value of filter [$key] - Range/DateRange can contain only [from/to => ...] values"
);
}
}
Expand Down

0 comments on commit b0598bc

Please sign in to comment.