From 1aa564960d91ad90a88f47fcbf9c96b8e4ba67d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 8 Dec 2025 16:18:31 +0100 Subject: [PATCH] feat: body dimensions optional --- src/Form/BodyDimensionsType.php | 4 ++ .../ParticipantFieldOptionsProvider.php | 3 ++ .../Constraints/ParticipantValidator.php | 17 ------- templates/booking/_participant_form.html.twig | 1 + .../Constraints/ParticipantValidatorTest.php | 50 +------------------ 5 files changed, 10 insertions(+), 65 deletions(-) diff --git a/src/Form/BodyDimensionsType.php b/src/Form/BodyDimensionsType.php index d459d57..f5cc370 100644 --- a/src/Form/BodyDimensionsType.php +++ b/src/Form/BodyDimensionsType.php @@ -60,6 +60,10 @@ class BodyDimensionsType extends AbstractType 'height_required' => false, 'weight_required' => false, 'shoeSize_required' => false, + 'help' => 'Du kannst die Daten auch später nachreichen', + 'help_attr' => [ + 'class' => 'lg:col-span-3 text-sm -mt-2 px-2', + ], ]); $resolver->setAllowedTypes('height_required', 'bool'); diff --git a/src/Form/Service/ParticipantFieldOptionsProvider.php b/src/Form/Service/ParticipantFieldOptionsProvider.php index e26aa40..35de9c6 100644 --- a/src/Form/Service/ParticipantFieldOptionsProvider.php +++ b/src/Form/Service/ParticipantFieldOptionsProvider.php @@ -298,6 +298,9 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider 'maxlength' => 20, ], 'help' => 'Bitte gib das Kennzeichen deines Fahrzeugs an. Du kannst es aber auch später nachreichen.', + 'help_attr' => [ + 'class' => 'text-sm px-2 mt-2', + ], 'sanitize_html' => true, ]; diff --git a/src/Validator/Constraints/ParticipantValidator.php b/src/Validator/Constraints/ParticipantValidator.php index baf5fba..068ee23 100644 --- a/src/Validator/Constraints/ParticipantValidator.php +++ b/src/Validator/Constraints/ParticipantValidator.php @@ -13,26 +13,9 @@ class ParticipantValidator extends ConstraintValidator /** @var ParticipantDto $participant */ $participant = $value; - $this->assertBodyMeasurementsValid($participant); $this->assertPickupSelected($participant); } - public function assertBodyMeasurementsValid(ParticipantDto $participant): void - { - if (0 === count($participant->rentals)) { - return; - } - - foreach (['height', 'shoeSize', 'weight'] as $property) { - if (empty($participant->{$property})) { - $this->context->buildViolation('Bitte angeben wegen Leihmaterial') - ->atPath($property) - ->addViolation() - ; - } - } - } - public function assertPickupSelected(ParticipantDto $participant): void { // Check if either outbound or inbound transportation is bus diff --git a/templates/booking/_participant_form.html.twig b/templates/booking/_participant_form.html.twig index 28fca6a..b0af89a 100644 --- a/templates/booking/_participant_form.html.twig +++ b/templates/booking/_participant_form.html.twig @@ -334,6 +334,7 @@ {{ form_row(form.bodyDimensions.height) }} {{ form_row(form.bodyDimensions.shoeSize) }} {{ form_row(form.bodyDimensions.weight) }} + {{ form_help(form.bodyDimensions) }} {% endif %} diff --git a/tests/Validator/Constraints/ParticipantValidatorTest.php b/tests/Validator/Constraints/ParticipantValidatorTest.php index 45f069a..30a94a9 100644 --- a/tests/Validator/Constraints/ParticipantValidatorTest.php +++ b/tests/Validator/Constraints/ParticipantValidatorTest.php @@ -17,20 +17,7 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase return new ParticipantValidator(); } - public function testParticipantWithoutRentalsPassesBodyMeasurementValidation(): void - { - $participant = $this->createValidParticipant(); - $participant->rentals = []; // No rentals, so body measurements not required - $participant->height = null; - $participant->weight = null; - $participant->shoeSize = null; - - $this->validator->validate($participant, new Participant()); - - $this->assertNoViolation(); - } - - public function testParticipantWithRentalsButNoBodyMeasurementsFailsValidation(): void + public function testParticipantWithRentalsButNoBodyMeasurementsPassesValidation(): void { $participant = $this->createValidParticipant(); $participant->rentals = [$this->createMockService()]; @@ -40,40 +27,7 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase $this->validator->validate($participant, new Participant()); - $this->buildViolation('Bitte angeben wegen Leihmaterial') - ->atPath('property.path.height') - ->buildNextViolation('Bitte angeben wegen Leihmaterial') - ->atPath('property.path.shoeSize') - ->buildNextViolation('Bitte angeben wegen Leihmaterial') - ->atPath('property.path.weight') - ->assertRaised(); - } - - public function testParticipantWithRentalsAndPartialBodyMeasurementsFailsValidation(): void - { - $participant = $this->createValidParticipant(); - $participant->rentals = [$this->createMockService()]; - $participant->height = '175'; - $participant->weight = null; // Missing - $participant->shoeSize = '42'; - - $this->validator->validate($participant, new Participant()); - - $this->buildViolation('Bitte angeben wegen Leihmaterial') - ->atPath('property.path.weight') - ->assertRaised(); - } - - public function testParticipantWithRentalsAndCompleteBodyMeasurementsPassesValidation(): void - { - $participant = $this->createValidParticipant(); - $participant->rentals = [$this->createMockService()]; - $participant->height = '175'; - $participant->weight = '70'; - $participant->shoeSize = '42'; - - $this->validator->validate($participant, new Participant()); - + // Body measurements are optional and can be provided later $this->assertNoViolation(); }