wip: rentals insurance field
This commit is contained in:
@@ -297,4 +297,72 @@ class CustomFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
}
|
||||
```
|
||||
|
||||
## Current Implementation Examples
|
||||
|
||||
### Body Dimensions and Rental Insurance Conditional Fields
|
||||
|
||||
The current system implements sophisticated conditional field visibility for body dimensions and rental insurance:
|
||||
|
||||
```php
|
||||
// CreateFieldStateProvider.php
|
||||
protected function registerFieldStateConditions(): void
|
||||
{
|
||||
$rentalCondition = new RentalSelectionCondition();
|
||||
|
||||
// Hide body dimensions section unless rental services are selected
|
||||
$this->fieldStateConditions['bodyDimensions'] = [
|
||||
'hidden' => CompositeCondition::not($rentalCondition),
|
||||
];
|
||||
|
||||
// Hide rental insurance unless rental services are selected
|
||||
$this->fieldStateConditions['rentalInsurance'] = [
|
||||
'hidden' => CompositeCondition::not($rentalCondition),
|
||||
];
|
||||
|
||||
// Hide parking unless outbound transportation is PKW (car)
|
||||
$this->fieldStateConditions['parking'] = [
|
||||
'hidden' => CompositeCondition::not(
|
||||
ServiceSubTypeCondition::equals('transportationOutbound', DirectionMapper::SUBTYPE_CAR_API)
|
||||
),
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
### Rental Insurance Checkbox Implementation
|
||||
|
||||
The rental insurance field demonstrates the checkbox pattern used for service selection:
|
||||
|
||||
```php
|
||||
// Field Options Provider
|
||||
$this->fieldOptionProviders['rentalInsurance'] = fn (BookingDtoInterface $bookingDto, int $participantIndex, array $options = []) => [
|
||||
'label' => $this->getRentalInsuranceCheckboxLabel($rentalInsuranceServices),
|
||||
'required' => false,
|
||||
'property_path' => 'rentalInsuranceSelected', // Maps to boolean property
|
||||
];
|
||||
|
||||
// Field Handler Processing
|
||||
public function processField(array $submittedData, BookingDtoInterface $bookingDto, int $participantIndex): void
|
||||
{
|
||||
$isRentalInsuranceSelected = (bool) $this->getFieldValue($submittedData, $this->getFieldName());
|
||||
|
||||
// Store boolean value for form state
|
||||
$participant->rentalInsuranceSelected = $isRentalInsuranceSelected;
|
||||
|
||||
// Store Service object for pricing calculations
|
||||
if ($isRentalInsuranceSelected) {
|
||||
$participant->rentalInsurance = $this->findRentalInsuranceService($bookingDto);
|
||||
} else {
|
||||
$participant->rentalInsurance = null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Benefits of Current Architecture
|
||||
|
||||
1. **Clean Separation**: Boolean properties handle form state, Service objects handle business logic
|
||||
2. **Automatic Pricing Integration**: Service objects are automatically included in pricing calculations
|
||||
3. **Dynamic Visibility**: Fields appear/disappear based on related selections
|
||||
4. **Consistent UX**: Checkbox pattern provides intuitive user interface
|
||||
5. **Validation-Free**: Conditional visibility eliminates need for complex validation rules
|
||||
|
||||
This system provides a powerful, maintainable foundation for complex conditional field behavior while maintaining clean separation of concerns and extensibility.
|
||||
Reference in New Issue
Block a user