$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 transportation 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; } $selectedTransportation = $this->getFieldValue($submittedData, $this->getFieldName()); // Get available inbound transportation services $availableServices = $bookingDto->travel->getTransportationServicesByDirection( DirectionMapper::INBOUND_TRAVEL, true // filter available ); // Validate and convert selection to Service object $validSelection = null; if (null !== $selectedTransportation) { $validSelection = $this->findValidTransportationService( $selectedTransportation, $availableServices ); } // Update participant with validated selection $participant->transportationInbound = $validSelection; } /** * Finds a valid transportation service from available services. * * @param mixed $selectedServiceId The submitted service ID * @param array $availableServices Array of available transportation services * * @return Service|null The valid service object, or null if invalid */ private function findValidTransportationService( mixed $selectedServiceId, array $availableServices, ): ?Service { if (null === $selectedServiceId || false === is_string($selectedServiceId) && false === is_int($selectedServiceId)) { return null; } $serviceId = (int) $selectedServiceId; foreach ($availableServices as $service) { if ($service->id === $serviceId) { return $service; } } return null; } }