$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; // Always process to handle deselection cases } public function processField(array $submittedData, BookingDto $bookingDto, int $participantIndex): void { $participant = $this->getParticipant($bookingDto, $participantIndex); if (null === $participant) { return; } $selectedBoard = $this->getFieldValue($submittedData, $this->getFieldName()) ?? []; // Get available board options from travel data (includes booked options in edit mode) $availableBoard = $this->getAvailableServicesWithBooked( $bookingDto, $participantIndex, Constants::TOKEN_BOARD ); $validSelections = $this->filterValidServiceSelections( $selectedBoard, $availableBoard, $bookingDto, $participantIndex ); $participant->board = $validSelections; } private function filterValidServiceSelections( array $selectedServices, array $availableServices, BookingDto $bookingDto, int $participantIndex, ): array { $validSelections = []; foreach ($selectedServices as $selectedService) { if ($this->isServiceValidForParticipant($selectedService, $availableServices, $bookingDto, $participantIndex)) { // Convert the selected service ID/data back to the actual Service object $serviceObject = $this->findServiceInAvailableServices($selectedService, $availableServices); if (null !== $serviceObject) { $validSelections[] = $serviceObject; } } } return $validSelections; } 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 (false === $ageEvaluator->canEvaluate($service)) { return true; } return $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex); } }