mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
DX: Add validation to PickRolingDateType
It is not possible to pick a fixed date when not setting a fixed date
This commit is contained in:
parent
c7f740d5d7
commit
4e3c93cdd3
@ -17,6 +17,8 @@ use Symfony\Component\Form\AbstractType;
|
|||||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\Validator\Constraints\Callback;
|
||||||
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
|
||||||
class PickRollingDateType extends AbstractType
|
class PickRollingDateType extends AbstractType
|
||||||
{
|
{
|
||||||
@ -45,6 +47,21 @@ class PickRollingDateType extends AbstractType
|
|||||||
$resolver->setDefaults([
|
$resolver->setDefaults([
|
||||||
'class' => RollingDate::class,
|
'class' => RollingDate::class,
|
||||||
'empty_data' => new RollingDate(RollingDate::T_TODAY),
|
'empty_data' => new RollingDate(RollingDate::T_TODAY),
|
||||||
|
'constraints' => [
|
||||||
|
new Callback([$this, 'validate'])
|
||||||
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function validate($data, ExecutionContextInterface $context, $payload): void
|
||||||
|
{
|
||||||
|
/** @var RollingDate $data */
|
||||||
|
if (RollingDate::T_FIXED_DATE === $data->getRoll() && null === $data->getFixedDate()) {
|
||||||
|
$context
|
||||||
|
->buildViolation('rolling_date.When fixed date is selected, you must provide a date')
|
||||||
|
->atPath('roll')
|
||||||
|
->addViolation()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,12 +84,12 @@ class RollingDate
|
|||||||
$this->fixedDate = $fixedDate;
|
$this->fixedDate = $fixedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFixedDate(): DateTimeImmutable
|
public function getFixedDate(): ?DateTimeImmutable
|
||||||
{
|
{
|
||||||
return $this->fixedDate;
|
return $this->fixedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPivotDate(): ?DateTimeImmutable
|
public function getPivotDate(): DateTimeImmutable
|
||||||
{
|
{
|
||||||
return $this->pivotDate;
|
return $this->pivotDate;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user