From 5642193610004e3996ceb8bf0ecd7a84b37e4b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 24 Sep 2025 10:59:23 +0200 Subject: [PATCH] feat: validate room selection --- src/Form/Model/BookingCreateDto.php | 12 ++++++++++++ templates/booking/create_step_1.html.twig | 1 + 2 files changed, 13 insertions(+) diff --git a/src/Form/Model/BookingCreateDto.php b/src/Form/Model/BookingCreateDto.php index d2626b2..3a5265a 100644 --- a/src/Form/Model/BookingCreateDto.php +++ b/src/Form/Model/BookingCreateDto.php @@ -4,6 +4,7 @@ namespace App\Form\Model; use App\BusProNet\Model\Travel; use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Component\Validator\Context\ExecutionContextInterface; class BookingCreateDto implements BookingDtoInterface { @@ -49,4 +50,15 @@ class BookingCreateDto implements BookingDtoInterface { return $this->participants[$index] ?? null; } + + #[Assert\Callback(callback: 'validateRoomSelection', groups: ['booking_create_step_1'])] + public function validateRoomSelection(ExecutionContextInterface $context): void + { + $selectedRooms = $this->getSelectedRooms(); + + if (0 === count($selectedRooms)) { + $context->buildViolation('Bitte mindestens ein Zimmer/Bett auswählen') + ->addViolation(); + } + } } diff --git a/templates/booking/create_step_1.html.twig b/templates/booking/create_step_1.html.twig index deedf8e..4d751cd 100644 --- a/templates/booking/create_step_1.html.twig +++ b/templates/booking/create_step_1.html.twig @@ -9,6 +9,7 @@ Unterkunft {{ form_start(form) }} + {{ form_errors(form) }} {% if groupedRooms.by_room is not empty %}

Zimmer