From f5f5d43ab5d1d4c9689d67cfc93f698fe235d436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 25 Nov 2025 17:30:23 +0100 Subject: [PATCH] feat: conditionally render room assignment field in participant edit form --- .../Condition/BookingModeCondition.php | 43 +++++++++++++++++++ src/Form/Service/CreateFieldStateProvider.php | 5 ++- src/Form/Service/EditFieldStateProvider.php | 9 ++-- templates/booking/_participant_form.html.twig | 34 ++++++++------- 4 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 src/Form/Service/Condition/BookingModeCondition.php diff --git a/src/Form/Service/Condition/BookingModeCondition.php b/src/Form/Service/Condition/BookingModeCondition.php new file mode 100644 index 0000000..1df1671 --- /dev/null +++ b/src/Form/Service/Condition/BookingModeCondition.php @@ -0,0 +1,43 @@ +mode === $bookingDto->getMode(); + } + + public function getDependentFields(): array + { + return []; + } + + public function getDescription(): string + { + return sprintf('Returns true when booking is in %s mode', $this->mode); + } +} diff --git a/src/Form/Service/CreateFieldStateProvider.php b/src/Form/Service/CreateFieldStateProvider.php index 82c4837..5f406e0 100644 --- a/src/Form/Service/CreateFieldStateProvider.php +++ b/src/Form/Service/CreateFieldStateProvider.php @@ -263,8 +263,11 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider 'required' => new ApplicantCondition(), ]; - // Render assignedRoomId field as static text when only one room type is selected (auto-assigned by RoomAssignmentService) + // Room assignment field: + // - Hidden until date of birth is provided (age determines room eligibility, e.g., Baby rooms) + // - Rendered as static text when only one room type is selected (auto-assigned by RoomAssignmentService) $this->fieldStateConditions['assignedRoomId'] = [ + 'hidden' => CompositeCondition::not($dateOfBirthProvidedCondition), 'static_text' => new SingleRoomTypeCondition(), ]; diff --git a/src/Form/Service/EditFieldStateProvider.php b/src/Form/Service/EditFieldStateProvider.php index 27aae15..23ba391 100644 --- a/src/Form/Service/EditFieldStateProvider.php +++ b/src/Form/Service/EditFieldStateProvider.php @@ -5,10 +5,12 @@ declare(strict_types=1); namespace App\Form\Service; use App\BusProNet\Utility\DirectionMapper; +use App\Form\Model\BookingDto; use App\Form\Service\Abstract\AbstractFieldStateProvider; use App\Form\Service\Condition\AdditionalServicesMutabilityCondition; use App\Form\Service\Condition\ApplicantCondition; use App\Form\Service\Condition\AuthenticatedUserPersonalDataCondition; +use App\Form\Service\Condition\BookingModeCondition; use App\Form\Service\Condition\CompositeCondition; use App\Form\Service\Condition\DateOfBirthProvidedCondition; use App\Form\Service\Condition\FieldValueCondition; @@ -16,7 +18,6 @@ use App\Form\Service\Condition\PersonalDataMutabilityCondition; use App\Form\Service\Condition\PickupsMutabilityCondition; use App\Form\Service\Condition\RentalSelectionCondition; use App\Form\Service\Condition\ServiceSubTypeCondition; -use App\Form\Service\Condition\SingleRoomTypeCondition; use App\Form\Service\Condition\SkiPassSelectionCondition; use App\Form\Service\Condition\TransportationServicesMutabilityCondition; @@ -97,10 +98,10 @@ class EditFieldStateProvider extends AbstractFieldStateProvider 'static_text' => $personalDataHiddenCondition, ]; - // Render assignedRoomId field as static text when only one room type is selected (auto-assigned by RoomAssignmentService) - // Same logic as create mode - render as static text when only one room type available + // Room assignments are fixed in edit mode - always render as static text + // The assignedRoomId value passes through unchanged from the loaded booking data $this->fieldStateConditions['assignedRoomId'] = [ - 'static_text' => new SingleRoomTypeCondition(), + 'static_text' => new BookingModeCondition(BookingDto::MODE_EDIT), ]; // Conditional visibility for service fields (same as create flow) diff --git a/templates/booking/_participant_form.html.twig b/templates/booking/_participant_form.html.twig index a933582..6116f06 100644 --- a/templates/booking/_participant_form.html.twig +++ b/templates/booking/_participant_form.html.twig @@ -134,22 +134,24 @@ {% endif %} - {# Room assignment #} -
- {% set assignedRoom = bookingDto.travel.getRoomById(form.vars.data.participant.assignedRoomId) %} - {% set roomLabel = assignedRoom ? assignedRoom.label : 'Kein Zimmer zugewiesen' %} - {{ macros.field_or_static(form, 'assignedRoomId', 'Zimmer', roomLabel, bookingDto, participantIndex, { - 'attr': { - 'hx-trigger': 'change', - 'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})), - 'hx-target': '#main-content', - 'hx-swap': 'innerHTML' - } - }) }} - {% if form.remarksRoom is defined %} - {{ form_row(form.remarksRoom) }} - {% endif %} -
+ {# Room assignment - hidden until date of birth is provided, or shown as static text in edit mode #} + {% if form.assignedRoomId is defined or is_static_text('assignedRoomId', bookingDto, participantIndex) %} +
+ {% set assignedRoom = bookingDto.travel.getRoomById(form.vars.data.participant.assignedRoomId) %} + {% set roomLabel = assignedRoom ? assignedRoom.label : 'Kein Zimmer zugewiesen' %} + {{ macros.field_or_static(form, 'assignedRoomId', 'Zimmer', roomLabel, bookingDto, participantIndex, { + 'attr': { + 'hx-trigger': 'change', + 'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})), + 'hx-target': '#main-content', + 'hx-swap': 'innerHTML' + } + }) }} + {% if form.remarksRoom is defined %} + {{ form_row(form.remarksRoom) }} + {% endif %} +
+ {% endif %} {# Eligibility checks #} {% set participantData = form.vars.data.participant %}