diff --git a/src/Bundle/ChillMainBundle/Export/DataTransformerFilterInterface.php b/src/Bundle/ChillMainBundle/Export/DataTransformerInterface.php similarity index 64% rename from src/Bundle/ChillMainBundle/Export/DataTransformerFilterInterface.php rename to src/Bundle/ChillMainBundle/Export/DataTransformerInterface.php index 055ee2edc..ed34bc9d6 100644 --- a/src/Bundle/ChillMainBundle/Export/DataTransformerFilterInterface.php +++ b/src/Bundle/ChillMainBundle/Export/DataTransformerInterface.php @@ -16,10 +16,10 @@ namespace Chill\MainBundle\Export; * * This interface defines a method for transforming filter's form data before it is processed. * - * You can implement this interface on @see{FilterInterface}, to allow to transform existing data in saved exports - * and replace it with some default values. + * You can implement this interface on @see{FilterInterface} or @see{AggregatorInterface}, to allow to transform existing data in saved exports + * and replace it with some default values, or new default values. */ -interface DataTransformerFilterInterface +interface DataTransformerInterface { public function transformData(?array $before): array; } diff --git a/src/Bundle/ChillMainBundle/Form/Type/Export/AggregatorType.php b/src/Bundle/ChillMainBundle/Form/Type/Export/AggregatorType.php index 1ea01d5f8..89d4586ce 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Export/AggregatorType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/Export/AggregatorType.php @@ -11,7 +11,9 @@ declare(strict_types=1); namespace Chill\MainBundle\Form\Type\Export; +use Chill\MainBundle\Export\DataTransformerInterface; 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; @@ -19,11 +21,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; class AggregatorType extends AbstractType { - public function __construct() - { - } - - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $exportManager = $options['export_manager']; $aggregator = $exportManager->getAggregator($options['aggregator_alias']); @@ -34,17 +32,26 @@ class AggregatorType extends AbstractType 'required' => false, ]); - $filterFormBuilder = $builder->create('form', FormType::class, [ + $aggregatorFormBuilder = $builder->create('form', FormType::class, [ 'compound' => true, 'required' => false, 'error_bubbling' => false, ]); - $aggregator->buildForm($filterFormBuilder); + $aggregator->buildForm($aggregatorFormBuilder); - $builder->add($filterFormBuilder); + if ($aggregator instanceof DataTransformerInterface) { + $aggregatorFormBuilder->addViewTransformer(new CallbackTransformer( + fn (?array $data) => $data, + function (?array $data) use ($aggregator) { + return $aggregator->transformData($data); + }, + )); + } + + $builder->add($aggregatorFormBuilder); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired('aggregator_alias') ->setRequired('export_manager') diff --git a/src/Bundle/ChillMainBundle/Form/Type/Export/FilterType.php b/src/Bundle/ChillMainBundle/Form/Type/Export/FilterType.php index 4e0976c12..5ac876bfe 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Export/FilterType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/Export/FilterType.php @@ -11,7 +11,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Form\Type\Export; -use Chill\MainBundle\Export\DataTransformerFilterInterface; +use Chill\MainBundle\Export\DataTransformerInterface; use Chill\MainBundle\Export\FilterInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\CallbackTransformer; @@ -45,7 +45,7 @@ class FilterType extends AbstractType ]); $filter->buildForm($filterFormBuilder); - if ($filter instanceof DataTransformerFilterInterface) { + if ($filter instanceof DataTransformerInterface) { $filterFormBuilder->addViewTransformer(new CallbackTransformer( fn (?array $data) => $data, function (?array $data) use ($filter) { diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php index 120d0a70e..c958272fc 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php @@ -13,7 +13,7 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Entity\User\UserJobHistory; use Chill\MainBundle\Entity\UserJob; -use Chill\MainBundle\Export\DataTransformerFilterInterface; +use Chill\MainBundle\Export\DataTransformerInterface; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Repository\UserJobRepositoryInterface; @@ -27,7 +27,7 @@ use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; -final readonly class UserJobFilter implements FilterInterface, DataTransformerFilterInterface +final readonly class UserJobFilter implements FilterInterface, DataTransformerInterface { private const PREFIX = 'acp_filter_user_job'; diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php index 7e6b1d185..5b8ff7526 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User\UserScopeHistory; +use Chill\MainBundle\Export\DataTransformerInterface; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Repository\ScopeRepositoryInterface; @@ -26,7 +27,7 @@ use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; -final readonly class UserScopeFilter implements FilterInterface +final readonly class UserScopeFilter implements FilterInterface, DataTransformerInterface { private const PREFIX = 'acp_filter_main_scope';