feat: make email optional for under-16 participants except applicant

This commit is contained in:
fromme committed 2026-10-19 09:18:22 +02:00
1 parent b958d1a371
commit 1d9c852113
18 files changed
+435 -336

No files matched your search

+32 -4
View File
@@ -80,11 +80,17 @@ class ParticipantDto
#[Assert\NotNull(message: 'Bitte angeben', groups: ['strict_required'])]
public ?\DateTimeImmutable $dateOfBirth = null;
// Every participant needs an email address: BusPro rejects the step-3 Anfrage with 650
// otherwise, children included. Under-16s have the applicant's address pre-filled by
// ParticipantEmailFieldHandler and may override it, but may not leave it blank.
// BusPro accepts a participant without an email address, so this is the only gate. Under-16s
// may leave it blank, everyone else needs one. An under-16 applicant needs one as well; that
// case depends on the booking and is enforced by BookingDto::validateFirstParticipantApplicant()
// and ParticipantEditDto::validateApplicant(). It stays a property constraint so the missing-field
// labels keep their order (see BookingEditPreFlightChecker).
#[Assert\Email(message: 'Bitte eine gültige E-Mail Adresse angeben', mode: 'strict', groups: ['booking_edit', 'booking_create'])]
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['strict_required'])]
#[Assert\When(
expression: 'not this.isChild()',
constraints: [new Assert\NotBlank(message: 'Bitte angeben')],
groups: ['strict_required'],
)]
public ?string $email = null;
public ?string $mobile = null;
@@ -530,6 +536,28 @@ class ParticipantDto
}
}
/**
* Validates that this person, as the booking's contact, has an email address.
*
* The property constraint on $email already holds everyone aged 16 or older (and anyone
* without a date of birth) to it, so this only adds the under-16 contact and never reports
* the same field twice. Like validateAddressFields(), the callers decide who the contact is.
*/
public function validateApplicantEmail(ExecutionContextInterface $context, string $pathPrefix = ''): void
{
if (false === $this->isChild()) {
return;
}
if (null !== $this->email && false === u($this->email)->trim()->isEmpty()) {
return;
}
$context->buildViolation('Bitte angeben')
->atPath($pathPrefix.'email')
->addViolation();
}
/**
* Validates that this person has a complete address.
*