$submittedData The submitted participant form data * @param string $mode The booking mode (BookingDto::MODE_CREATE or MODE_EDIT) * @param int $participantIndex The index of the participant being processed * * @return bool Always returns true for service selection fields */ public function shouldProcess(array $submittedData, string $mode, int $participantIndex): bool { return true; } /** * Processes the veg field for a specific participant. * * This method extracts the dietary preference selection from submitted form data, * validates the selection against any age constraints if present, and updates the * participant DTO with the valid selection. * * @param array $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 (null === $participant) { return; } $selectedVeg = $this->getFieldValue($submittedData, $this->getFieldName()); // Get available veg options from travel data (includes booked options in edit mode) $availableVegOptions = $this->getAvailableServicesWithBooked( $bookingDto, $participantIndex, Constants::TOKEN_VEG, true ); $validSelection = null; if (null !== $selectedVeg) { if ($this->isServiceValidForParticipant($selectedVeg, $availableVegOptions, $bookingDto, $participantIndex)) { $validSelection = $this->findServiceInAvailableServices($selectedVeg, $availableVegOptions); } } $participant->veg = $validSelection; } /** * Validates if a selected veg option is still valid for the participant. * * This method checks age constraints if they exist for the service. * * @param mixed $selectedService The selected veg option to validate * @param array $availableServices Array of available veg options * @param BookingDto $bookingDto The booking DTO for context * @param int $participantIndex The participant index for age evaluation * * @return bool True if the option is valid for the participant, false otherwise */ private function isServiceValidForParticipant( mixed $selectedService, array $availableServices, BookingDto $bookingDto, int $participantIndex, ): bool { $service = $this->findServiceInAvailableServices($selectedService, $availableServices); if (null === $service) { return false; } $ageEvaluator = new ServiceAgeEvaluator(); if ($ageEvaluator->canEvaluate($service)) { if (false === $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex)) { return false; } } return true; } }