diff --git a/src/Form/Service/Condition/RentalInsuranceAvailableCondition.php b/src/Form/Service/Condition/RentalInsuranceAvailableCondition.php new file mode 100644 index 0000000..978a8c0 --- /dev/null +++ b/src/Form/Service/Condition/RentalInsuranceAvailableCondition.php @@ -0,0 +1,65 @@ + $formData Current form data for condition evaluation + * + * @return bool True if rental insurance services are available, false otherwise + */ + public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool + { + if (null === $bookingDto->travel) { + return false; + } + + $services = $bookingDto->travel->getAdditionalServicesBySubTypes( + Constants::TOKEN_RENTAL_INSURANCE, + true + ); + + return false === empty($services); + } + + /** + * Returns field names that trigger re-evaluation of this condition. + * + * This condition depends on travel data which doesn't change during form interaction, + * so no fields trigger re-evaluation. + * + * @return string[] Empty array as this condition is static for a given travel + */ + public function getDependentFields(): array + { + return []; + } + + /** + * Returns a human-readable description of this condition. + * + * @return string A brief description of the condition logic + */ + public function getDescription(): string + { + return 'Rental insurance checkbox shown only when LVS services exist for travel'; + } +} diff --git a/src/Form/Service/CreateFieldStateProvider.php b/src/Form/Service/CreateFieldStateProvider.php index 892680e..54d4e83 100644 --- a/src/Form/Service/CreateFieldStateProvider.php +++ b/src/Form/Service/CreateFieldStateProvider.php @@ -17,6 +17,7 @@ use App\Form\Service\Condition\FieldValueCondition; use App\Form\Service\Condition\FinalBookingOnlyCondition; use App\Form\Service\Condition\FirstParticipantCondition; use App\Form\Service\Condition\MultipleParticipantsCondition; +use App\Form\Service\Condition\RentalInsuranceAvailableCondition; use App\Form\Service\Condition\RentalSelectionCondition; use App\Form\Service\Condition\RoomSelectionCondition; use App\Form\Service\Condition\ServiceSubTypeCondition; @@ -264,9 +265,13 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider ), ]; - // Show rental insurance only when rental services are selected (hidden by default) + // Show rental insurance only when rental services are selected AND LVS services exist (hidden by default) + $rentalInsuranceAvailableCondition = new RentalInsuranceAvailableCondition(); $this->fieldStateConditions['rentalInsurance'] = [ - 'hidden' => CompositeCondition::not($rentalCondition), + 'hidden' => CompositeCondition::or( + CompositeCondition::not($rentalCondition), + CompositeCondition::not($rentalInsuranceAvailableCondition) + ), ]; // Show license plate only when parking is selected (hidden by default) diff --git a/src/Form/Service/EditFieldStateProvider.php b/src/Form/Service/EditFieldStateProvider.php index 1617891..2d6b536 100644 --- a/src/Form/Service/EditFieldStateProvider.php +++ b/src/Form/Service/EditFieldStateProvider.php @@ -17,6 +17,7 @@ use App\Form\Service\Condition\FieldValueCondition; use App\Form\Service\Condition\FirstParticipantCondition; use App\Form\Service\Condition\PersonalDataMutabilityCondition; use App\Form\Service\Condition\PickupsMutabilityCondition; +use App\Form\Service\Condition\RentalInsuranceAvailableCondition; use App\Form\Service\Condition\RentalSelectionCondition; use App\Form\Service\Condition\RoomSelectionCondition; use App\Form\Service\Condition\ServiceSubTypeCondition; @@ -159,9 +160,13 @@ class EditFieldStateProvider extends AbstractFieldStateProvider 'readonly' => $additionalServicesMutabilityCondition, ]; - // Rental insurance - shown only when rentals selected, readonly if services not mutable + // Rental insurance - shown only when rentals selected AND LVS services exist, readonly if services not mutable + $rentalInsuranceAvailableCondition = new RentalInsuranceAvailableCondition(); $this->fieldStateConditions['rentalInsurance'] = [ - 'hidden' => CompositeCondition::not($rentalCondition), + 'hidden' => CompositeCondition::or( + CompositeCondition::not($rentalCondition), + CompositeCondition::not($rentalInsuranceAvailableCondition) + ), 'readonly' => $additionalServicesMutabilityCondition, ];