Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Config/Crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ public function autocomplete(bool $enable = true, ?callable $callback = null, ?s

public function setFilters(?FilterConfigDto $filters): self
{
$this->dto->setFiltersConfig($filters);
// 'null' means "no filters", which is represented by an empty filter config
// (CrudDto::setFiltersConfig() doesn't accept null values)
$this->dto->setFiltersConfig($filters ?? new FilterConfigDto());

return $this;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Config/CrudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\ClickTrigger;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FilterConfigDto;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\TranslatableMessage;

Expand Down Expand Up @@ -308,4 +309,12 @@ public function testSetDefaultRowActionDefaultTriggerWithInvalidString(string $c
$crudConfig = Crud::new();
$crudConfig->setDefaultRowActionTrigger($clickTrigger);
}

public function testSetFiltersAcceptsNull(): void
{
$crudConfig = Crud::new();
$crudConfig->setFilters(null);

$this->assertInstanceOf(FilterConfigDto::class, $crudConfig->getAsDto()->getFiltersConfig());
}
}
Loading