From 31cf383f9b291b8969d5f5192a4bd6a06a1d01cd Mon Sep 17 00:00:00 2001 From: tischsoic Date: Mon, 7 Oct 2024 12:57:31 +0200 Subject: [PATCH] IBX-9023: Add DateRangeData and DateRangeType --- src/lib/Form/Data/DateRangeData.php | 49 +++++++++++++++++++++++++++++ src/lib/Form/Type/DateRangeType.php | 36 +++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/lib/Form/Data/DateRangeData.php create mode 100644 src/lib/Form/Type/DateRangeType.php diff --git a/src/lib/Form/Data/DateRangeData.php b/src/lib/Form/Data/DateRangeData.php new file mode 100644 index 0000000000..26336fd7b4 --- /dev/null +++ b/src/lib/Form/Data/DateRangeData.php @@ -0,0 +1,49 @@ +min = $min; + $this->max = $max; + } + + public function isEmpty(): bool + { + return $this->min === null && $this->max === null; + } + + public function getMin(): ?DateTimeInterface + { + return $this->min; + } + + public function setMin(?DateTimeInterface $min): void + { + $this->min = $min; + } + + public function getMax(): ?DateTimeInterface + { + return $this->max; + } + + public function setMax(?DateTimeInterface $max): void + { + $this->max = $max; + } +} diff --git a/src/lib/Form/Type/DateRangeType.php b/src/lib/Form/Type/DateRangeType.php new file mode 100644 index 0000000000..d28fae2c65 --- /dev/null +++ b/src/lib/Form/Type/DateRangeType.php @@ -0,0 +1,36 @@ +add('min', DateTimePickerType::class, [ + 'required' => false, + ]); + + $builder->add('max', DateTimePickerType::class, [ + 'required' => false, + ]); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => DateRangeData::class, + 'translation_domain' => 'forms', + ]); + } +}