wip: dynamic services fields

This commit is contained in:
Björn Fromme
2026-03-16 11:59:09 +01:00
parent 7003c0d81b
commit 6bd483d768
21 changed files with 634 additions and 39 deletions
@@ -28,6 +28,30 @@ abstract class AbstractFieldStateProvider implements FieldStateProviderInterface
$this->registerFieldStateConditions();
}
/**
* Determines whether a field should be included in the form at all.
*
* Fields with 'hidden' state conditions should not be added to the form
* rather than being hidden with CSS. This method evaluates the hidden
* condition independently to allow early field exclusion.
*
* @param string $fieldName The name of the field to evaluate
* @param BookingDtoInterface $bookingDto The current booking data for context (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 the field should be included in the form, false if it should be excluded
*/
public function shouldIncludeField(string $fieldName, BookingDtoInterface $bookingDto, int $participantIndex, array $formData = []): bool
{
if (false === isset($this->fieldStateConditions[$fieldName]['hidden'])) {
return true; // No hidden condition means field should be included
}
$hiddenCondition = $this->fieldStateConditions[$fieldName]['hidden'];
return !$hiddenCondition->evaluate($bookingDto, $participantIndex, $formData);
}
/**
* Calculates the dynamic state for a specified field.
*
@@ -35,6 +59,9 @@ abstract class AbstractFieldStateProvider implements FieldStateProviderInterface
* state modifications. State conditions are organized by state type (readonly,
* disabled, etc.) and evaluated independently.
*
* Note: This method no longer handles 'hidden' state as fields should be
* excluded from the form entirely rather than hidden with CSS.
*
* @param string $fieldName The name of the field to evaluate
* @param BookingDtoInterface $bookingDto The current booking data for context (create or edit)
* @param int $participantIndex The index of the participant being evaluated
@@ -44,7 +71,7 @@ abstract class AbstractFieldStateProvider implements FieldStateProviderInterface
*/
public function getFieldState(string $fieldName, BookingDtoInterface $bookingDto, int $participantIndex, array $formData = []): array
{
if (!isset($this->fieldStateConditions[$fieldName])) {
if (false === isset($this->fieldStateConditions[$fieldName])) {
return [];
}
@@ -63,14 +90,11 @@ abstract class AbstractFieldStateProvider implements FieldStateProviderInterface
case 'required':
$stateModifications['required'] = true;
break;
case 'hidden':
$attributes['style'] = ($attributes['style'] ?? '').' display: none;';
break;
}
}
}
if (!empty($attributes)) {
if (false === empty($attributes)) {
$stateModifications['attr'] = $attributes;
}