mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +00:00
Add data transformation interface for filters
Introduced a new DataTransformerFilterInterface that allows transforming filter's form data before it is processed. Updated the FilterType file to add a view transformer if the filter implements this new interface. This new transformation process caters to transforming existing data in saved exports and replacing it with default values.
This commit is contained in:
@@ -11,8 +11,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Form\Type\Export;
|
||||
|
||||
use Chill\MainBundle\Export\DataTransformerFilterInterface;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -43,6 +45,15 @@ class FilterType extends AbstractType
|
||||
]);
|
||||
$filter->buildForm($filterFormBuilder);
|
||||
|
||||
if ($filter instanceof DataTransformerFilterInterface) {
|
||||
$filterFormBuilder->addViewTransformer(new CallbackTransformer(
|
||||
fn (?array $data) => $data,
|
||||
function (?array $data) use ($filter) {
|
||||
return $filter->transformData($data);
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
$builder->add($filterFormBuilder);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user