From c6b28e7f4e184085283b598b145899d37a972855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 13 Nov 2025 12:29:27 +0100 Subject: [PATCH] fix: don't validate insurance selection of participants when in bulk assignment --- src/Form/Model/ParticipantDto.php | 2 +- src/Form/Model/ParticipantEditDto.php | 50 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/Form/Model/ParticipantDto.php b/src/Form/Model/ParticipantDto.php index 87f6f0b..7a31195 100644 --- a/src/Form/Model/ParticipantDto.php +++ b/src/Form/Model/ParticipantDto.php @@ -105,7 +105,7 @@ class ParticipantDto public ?string $licensePlate = null; // Selected insurance for this participant (individual insurance selection per participant) - #[Assert\NotNull(message: 'Bitte auswählen', groups: ['strict_required'])] + // Note: Insurance validation is conditional - see ParticipantEditDto::validateInsuranceRequired() public ?Insurance $insurance = null; // Bulk insurance booking flag (applicant only: when checked, assigns same insurance type to all participants) diff --git a/src/Form/Model/ParticipantEditDto.php b/src/Form/Model/ParticipantEditDto.php index 5c3a4d5..2ae5a63 100644 --- a/src/Form/Model/ParticipantEditDto.php +++ b/src/Form/Model/ParticipantEditDto.php @@ -24,6 +24,56 @@ class ParticipantEditDto ) { } + /** + * Validates that insurance is selected when required. + * + * Insurance is required for all participants in create mode, EXCEPT for dependent + * participants when the applicant has enabled bulk insurance booking. In that case, + * the insurance field is hidden and will be automatically assigned by the bulk + * insurance handler. + * + * This validation only runs when strict_required group is active. + */ + #[Assert\Callback(groups: ['strict_required'])] + public function validateInsuranceRequired(ExecutionContextInterface $context): void + { + // Insurance is always required for applicant + if (true === $this->participant->isApplicant()) { + if (null === $this->participant->insurance) { + $context->buildViolation('Bitte auswählen') + ->atPath('participant.insurance') + ->addViolation(); + } + + return; + } + + // For dependent participants, check if bulk insurance is active + $applicant = $this->bookingContext->getParticipant(0); + if (null === $applicant) { + // Applicant not found - shouldn't happen, but validate insurance to be safe + if (null === $this->participant->insurance) { + $context->buildViolation('Bitte auswählen') + ->atPath('participant.insurance') + ->addViolation(); + } + + return; + } + + // If bulk insurance booking is active, skip validation (field is hidden, will be auto-assigned) + if (true === $applicant->bulkInsuranceBooking) { + return; + } + + // Bulk insurance not active - insurance is required + if (null === $this->participant->insurance) { + $context->buildViolation('Bitte auswählen') + ->atPath('participant.insurance') + ->addViolation(); + } + } + /** * Validates that adult participants have unique email addresses. *