$submittedData The submitted participant form data * @param int $participantIndex The index of the participant being processed * * @return bool Always returns true for parking selection fields */ public function shouldProcess(array $submittedData, int $participantIndex): bool { return true; // Always process for state changes } public function processField(array $submittedData, BookingDtoInterface $bookingDto, int $participantIndex): void { $participant = $this->getParticipant($bookingDto, $participantIndex); if (null === $participant) { return; } // Check if parking is applicable (at least one PKW direction) if (!$this->isParkingApplicable($participant)) { $participant->parking = null; // Clear parking for bus-only transport return; } $selectedParking = $this->getFieldValue($submittedData, $this->getFieldName()); // Get available parking services (subtype PAR) $availableParkingServices = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_PARKING, true); $validSelection = null; if (null !== $selectedParking) { $validSelection = $this->findValidParkingService($selectedParking, $availableParkingServices); } $participant->parking = $validSelection; } /** * Checks if parking is applicable based on transportation selections. * * @param object $participant The participant DTO * * @return bool True if parking is applicable, false otherwise */ private function isParkingApplicable(object $participant): bool { $outboundIsPkw = DirectionMapper::SUBTYPE_CAR_API === $participant->transportationOutbound?->subType; $inboundIsPkw = DirectionMapper::SUBTYPE_CAR_API === $participant->transportationInbound?->subType; return $outboundIsPkw || $inboundIsPkw; } /** * Finds a valid parking service from available parking services. * * @param mixed $selectedServiceId The submitted service ID * @param array $availableServices Array of available parking services * * @return Service|null The valid service object, or null if invalid */ private function findValidParkingService(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; } }