feat: use normalized checkbox values in field handlers

This commit is contained in:
Björn Fromme
2026-03-16 12:03:00 +01:00
parent 6abfa122e4
commit 40c0042158
6 changed files with 69 additions and 4 deletions
@@ -153,6 +153,21 @@ abstract class AbstractParticipantFieldHandler implements ParticipantFieldHandle
return is_numeric($value) ? (int) $value : null;
}
/**
* Normalizes a checkbox/form toggle value to a boolean.
*
* Form checkboxes may submit true, false, 1, 0, '1', '0', or be absent.
* This method treats only true, 1, and '1' as checked; everything else as unchecked.
*
* @param mixed $value The raw value from form submission
*
* @return bool True if the checkbox is considered checked, false otherwise
*/
protected function normalizeCheckboxValue(mixed $value): bool
{
return true === $value || 1 === $value || '1' === $value;
}
/**
* Returns field state modifications that should be applied after processing.
*
@@ -68,6 +68,6 @@ class ParticipantBulkInsuranceFieldHandler extends AbstractParticipantFieldHandl
// Get checkbox value from submitted data and store it
$bulkInsuranceBooking = $this->getFieldValue($submittedData, $this->getFieldName());
$participant->bulkInsuranceBooking = (bool) $bulkInsuranceBooking;
$participant->bulkInsuranceBooking = $this->normalizeCheckboxValue($bulkInsuranceBooking);
}
}
@@ -334,7 +334,7 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
// Check if bulk insurance booking is enabled
$bulkInsuranceBooking = $applicantData['bulkInsuranceBooking'] ?? false;
if (false === (bool) $bulkInsuranceBooking) {
if (false === $this->normalizeCheckboxValue($bulkInsuranceBooking)) {
return false;
}
@@ -66,7 +66,7 @@ class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
}
$parkingSelected = $this->getFieldValue($submittedData, $this->getFieldName());
$isParkingSelected = (bool) $parkingSelected;
$isParkingSelected = $this->normalizeCheckboxValue($parkingSelected);
// Store boolean value for backward compatibility
$participant->parking = $isParkingSelected;
@@ -100,7 +100,7 @@ class ParticipantRentalInsuranceFieldHandler extends AbstractParticipantFieldHan
// Extract checkbox value from submitted data (this comes from the rentalInsuranceSelected property)
$rentalInsuranceSelected = $this->getFieldValue($submittedData, $this->getFieldName());
$isRentalInsuranceSelected = (bool) $rentalInsuranceSelected;
$isRentalInsuranceSelected = $this->normalizeCheckboxValue($rentalInsuranceSelected);
// Store boolean value
$participant->rentalInsuranceSelected = $isRentalInsuranceSelected;