If you forget calling saveFilter and call filter directly, the $forms property in the service is empty, causing a notice in the filter method and making it not work.
We should add a check and raise an exception to ease debugging.
Good example:
<?php
public function action(Filter $filter): Response
{
$filter->saveFilter(MyFilterType::class, 'my_name');
$filters = $filter->filter('my_name');
// etc...
}
Bad example:
<?php
public function action(Filter $filter): Response
{
$filters = $filter->filter('my_name'); // <-- forgot saving the filter, not working!
// etc...
}
If you forget calling
saveFilterand callfilterdirectly, the$formsproperty in the service is empty, causing a notice in thefiltermethod and making it not work.We should add a check and raise an exception to ease debugging.
Good example:
Bad example: