fix: don't validate insurance selection of participants when in bulk assignment

This commit is contained in:
Björn Fromme
2026-03-16 11:59:11 +01:00
parent f01bb7d271
commit 778cf80e6b
2 changed files with 51 additions and 1 deletions
+1 -1
View File
@@ -105,7 +105,7 @@ class ParticipantDto
public ?string $licensePlate = null; public ?string $licensePlate = null;
// Selected insurance for this participant (individual insurance selection per participant) // 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; public ?Insurance $insurance = null;
// Bulk insurance booking flag (applicant only: when checked, assigns same insurance type to all participants) // Bulk insurance booking flag (applicant only: when checked, assigns same insurance type to all participants)
+50
View File
@@ -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. * Validates that adult participants have unique email addresses.
* *