$submittedData The submitted participant form data * @param BookingDto $bookingDto The booking DTO to update (create or edit) * @param int $participantIndex The index of the participant being processed */ public function processField(array $submittedData, BookingDto $bookingDto, int $participantIndex): void { $participant = $this->getParticipant($bookingDto, $participantIndex); if (false === $participant instanceof ParticipantDto) { return; } $submitted = $this->getFieldValue($submittedData, $this->getFieldName()); if (true === is_string($submitted)) { $participant->email = '' !== trim($submitted) ? trim($submitted) : null; } $this->applyApplicantEmail($bookingDto, $participant); } /** * Copies the applicant's address onto a child who has none of their own. */ public function applyApplicantEmail(BookingDto $bookingDto, ParticipantDto $participant): void { // Create mode only. An existing booking already carries whatever BusPro accepted, a // blank may be intended where personal data is optional, and participant[0] is not // reliably the applicant there. if (BookingDto::MODE_CREATE !== $bookingDto->getMode()) { return; } if (false === $participant->isChild()) { return; } $applicantEmail = $this->resolveApplicantEmail($bookingDto); if (null === $applicantEmail) { return; } // The applicant themselves never inherits, and on an ordinary booking that is participant[0]. if (true === $participant->isApplicant() && true === $bookingDto->applicantTravels) { return; } if (null === $participant->email || '' === trim($participant->email)) { $participant->email = $applicantEmail; } } private function resolveApplicantEmail(BookingDto $bookingDto): ?string { $applicant = $bookingDto->applicantTravels ? ($bookingDto->participants[0] ?? null) : $bookingDto->applicant; $email = $applicant?->email; if (null === $email || '' === trim($email)) { return null; } return trim($email); } }