$submittedData The submitted participant form data * @param int $participantIndex The index of the participant being processed * * @return bool Always returns true for service selection fields */ public function shouldProcess(array $submittedData, int $participantIndex): bool { return true; // Always process to handle deselection cases } /** * Processes the rentalInsurance field for a specific participant. * * This method extracts the rental insurance selection from submitted form data, * validates the selection against the participant's age constraints, and * updates the participant DTO with the valid selection. If the rental insurance * is no longer appropriate for the participant's age, it is automatically cleared. * * @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 { // Safely get the participant object, returning early if not found $participant = $this->getParticipant($bookingDto, $participantIndex); if (null === $participant) { return; } // Check if rental insurance should be visible based on skipass and rental selections $hasSkiPass = null !== $participant->skiPass; $hasRentals = false === empty($participant->rentals); if (false === $hasSkiPass || false === $hasRentals) { // If no skipass or no rentals are selected, clear rental insurance data $participant->rentalInsuranceSelected = false; $participant->rentalInsurance = null; return; } // Extract checkbox value from submitted data (this comes from the rentalInsuranceSelected property) $rentalInsuranceSelected = $this->getFieldValue($submittedData, $this->getFieldName()); $isRentalInsuranceSelected = (bool) $rentalInsuranceSelected; // Store boolean value $participant->rentalInsuranceSelected = $isRentalInsuranceSelected; // Store service object based on checkbox state for pricing calculations if (true === $isRentalInsuranceSelected) { $participant->rentalInsurance = $this->findRentalInsuranceService($bookingDto); } else { $participant->rentalInsurance = null; } } /** * Finds the rental insurance service from available services. * * Gets the first (and typically only) rental insurance service. * Returns null if no rental insurance services are available. * * @param BookingDto $bookingDto The booking DTO containing travel data * * @return Service|null The rental insurance service object, or null if not found */ private function findRentalInsuranceService(BookingDto $bookingDto): ?Service { $rentalInsuranceServices = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_RENTAL_INSURANCE, true, true); if (empty($rentalInsuranceServices)) { return null; } return reset($rentalInsuranceServices); // Get the first (and typically only) rental insurance service } }