From 6280453523b79673ea0b7a96c6d6660b548fa96e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 5 Nov 2023 23:29:33 +0100 Subject: [PATCH] Fix activity date filter: validation of form using RollingDate --- .../unreleased/Fixed-20231105-232608.yaml | 5 +++ .../Export/Filter/ActivityDateFilter.php | 44 ------------------- 2 files changed, 5 insertions(+), 44 deletions(-) create mode 100644 .changes/unreleased/Fixed-20231105-232608.yaml diff --git a/.changes/unreleased/Fixed-20231105-232608.yaml b/.changes/unreleased/Fixed-20231105-232608.yaml new file mode 100644 index 000000000..dba0bfd70 --- /dev/null +++ b/.changes/unreleased/Fixed-20231105-232608.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: Fix filter "activity by date" +time: 2023-11-05T23:26:08.685518729+01:00 +custom: + Issue: "184" diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php index a67d0155d..e3d7796d3 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php @@ -13,16 +13,12 @@ namespace Chill\ActivityBundle\Export\Filter; use Chill\ActivityBundle\Export\Declarations; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\Export\FilterType; use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Form\FormError; -use Symfony\Component\Form\FormEvent; -use Symfony\Component\Form\FormEvents; use Symfony\Contracts\Translation\TranslatorInterface; class ActivityDateFilter implements FilterInterface @@ -74,46 +70,6 @@ class ActivityDateFilter implements FilterInterface ->add('date_to', PickRollingDateType::class, [ 'label' => 'Activities before this date', ]); - - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { - /** @var \Symfony\Component\Form\FormInterface $filterForm */ - $filterForm = $event->getForm()->getParent(); - $enabled = $filterForm->get(FilterType::ENABLED_FIELD)->getData(); - - if (true === $enabled) { - // if the filter is enabled, add some validation - $form = $event->getForm(); - $date_from = $form->get('date_from')->getData(); - $date_to = $form->get('date_to')->getData(); - - // check that fields are not empty - if (null === $date_from) { - $form->get('date_from')->addError(new FormError( - $this->translator->trans('This field ' - .'should not be empty') - )); - } - - if (null === $date_to) { - $form->get('date_to')->addError(new FormError( - $this->translator->trans('This field ' - .'should not be empty') - )); - } - - // check that date_from is before date_to - if ( - (null !== $date_from && null !== $date_to) - && $date_from >= $date_to - ) { - $form->get('date_to')->addError(new FormError( - $this->translator->trans('This date should be after ' - .'the date given in "Implied in an activity after ' - .'this date" field') - )); - } - } - }); } public function getFormDefaultData(): array