fix: ensure rental insurance is selectable when insurance is available

addresses #869bp9ev5
This commit is contained in:
Björn Fromme
2026-01-07 17:31:20 +01:00
parent 6fee5c048a
commit ddb876bc1c
3 changed files with 79 additions and 4 deletions
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace App\Form\Service\Condition;
use App\BusProNet\Constants;
use App\Form\Model\BookingDto;
use App\Form\Service\Contract\FieldConditionInterface;
/**
* Condition that evaluates whether rental insurance services are available for the travel.
*
* This condition checks if the travel has any LVS (rental insurance) services available.
* The rental insurance checkbox should only be shown when both rental equipment is selected
* AND rental insurance services actually exist for the travel period.
*/
class RentalInsuranceAvailableCondition implements FieldConditionInterface
{
/**
* Evaluates whether rental insurance services are available for the travel.
*
* @param BookingDto $bookingDto The current booking data (create or edit)
* @param int $participantIndex The index of the participant being evaluated
* @param array<string, mixed> $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';
}
}
@@ -17,6 +17,7 @@ use App\Form\Service\Condition\FieldValueCondition;
use App\Form\Service\Condition\FinalBookingOnlyCondition; use App\Form\Service\Condition\FinalBookingOnlyCondition;
use App\Form\Service\Condition\FirstParticipantCondition; use App\Form\Service\Condition\FirstParticipantCondition;
use App\Form\Service\Condition\MultipleParticipantsCondition; use App\Form\Service\Condition\MultipleParticipantsCondition;
use App\Form\Service\Condition\RentalInsuranceAvailableCondition;
use App\Form\Service\Condition\RentalSelectionCondition; use App\Form\Service\Condition\RentalSelectionCondition;
use App\Form\Service\Condition\RoomSelectionCondition; use App\Form\Service\Condition\RoomSelectionCondition;
use App\Form\Service\Condition\ServiceSubTypeCondition; 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'] = [ $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) // Show license plate only when parking is selected (hidden by default)
+7 -2
View File
@@ -17,6 +17,7 @@ use App\Form\Service\Condition\FieldValueCondition;
use App\Form\Service\Condition\FirstParticipantCondition; use App\Form\Service\Condition\FirstParticipantCondition;
use App\Form\Service\Condition\PersonalDataMutabilityCondition; use App\Form\Service\Condition\PersonalDataMutabilityCondition;
use App\Form\Service\Condition\PickupsMutabilityCondition; use App\Form\Service\Condition\PickupsMutabilityCondition;
use App\Form\Service\Condition\RentalInsuranceAvailableCondition;
use App\Form\Service\Condition\RentalSelectionCondition; use App\Form\Service\Condition\RentalSelectionCondition;
use App\Form\Service\Condition\RoomSelectionCondition; use App\Form\Service\Condition\RoomSelectionCondition;
use App\Form\Service\Condition\ServiceSubTypeCondition; use App\Form\Service\Condition\ServiceSubTypeCondition;
@@ -159,9 +160,13 @@ class EditFieldStateProvider extends AbstractFieldStateProvider
'readonly' => $additionalServicesMutabilityCondition, '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'] = [ $this->fieldStateConditions['rentalInsurance'] = [
'hidden' => CompositeCondition::not($rentalCondition), 'hidden' => CompositeCondition::or(
CompositeCondition::not($rentalCondition),
CompositeCondition::not($rentalInsuranceAvailableCondition)
),
'readonly' => $additionalServicesMutabilityCondition, 'readonly' => $additionalServicesMutabilityCondition,
]; ];