feat: configurable choices for body dimensions

closes #8697phk21
This commit is contained in:
Björn Fromme
2025-12-10 13:48:47 +01:00
parent 145a08e511
commit 0e9c5e6e1a
7 changed files with 174 additions and 22 deletions
+21 -20
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Form;
use App\Form\Model\ParticipantDto;
@@ -12,44 +14,35 @@ class BodyDimensionsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$shoeSizeChoices = array_combine(
range($options['shoe_size_min'], $options['shoe_size_max']),
range($options['shoe_size_min'], $options['shoe_size_max'])
);
$builder
->add('height', ChoiceType::class, [
'label' => 'Körpergröße',
'required' => $options['height_required'] ?? false,
'required' => $options['height_required'],
'expanded' => false,
'multiple' => false,
'placeholder' => 'Keine Angabe',
'choices' => [
'bis 148cm' => '-148',
'149 - 157cm' => '149-157',
'158 - 166cm' => '158-166',
'167 - 178cm' => '167-178',
'179 - 194cm' => '179-197',
'195cm oder mehr' => '195cm+',
],
'choices' => $options['height_choices'],
])
->add('shoeSize', ChoiceType::class, [
'label' => 'Schuhgröße',
'required' => $options['shoeSize_required'] ?? false,
'required' => $options['shoeSize_required'],
'expanded' => false,
'multiple' => false,
'placeholder' => 'Keine Angabe',
'choices' => array_combine(range(36, 48), range(36, 48)),
'choices' => $shoeSizeChoices,
])
->add('weight', ChoiceType::class, [
'label' => 'Gewicht',
'required' => $options['weight_required'] ?? false,
'required' => $options['weight_required'],
'expanded' => false,
'multiple' => false,
'placeholder' => 'Keine Angabe',
'choices' => [
'42 - 48kg' => '42-48',
'49 - 57kg' => '49-57',
'58 - 66kg' => '58-66',
'67 - 78kg' => '67-78',
'79 - 94kg' => '79-94',
'95kg oder mehr' => '95k+',
],
'choices' => $options['weight_choices'],
]);
}
@@ -60,6 +53,10 @@ class BodyDimensionsType extends AbstractType
'height_required' => false,
'weight_required' => false,
'shoeSize_required' => false,
'height_choices' => [],
'weight_choices' => [],
'shoe_size_min' => 36,
'shoe_size_max' => 48,
'help' => 'Du kannst die Daten auch später nachreichen',
'help_attr' => [
'class' => 'lg:col-span-3 text-sm -mt-2 px-2',
@@ -69,5 +66,9 @@ class BodyDimensionsType extends AbstractType
$resolver->setAllowedTypes('height_required', 'bool');
$resolver->setAllowedTypes('weight_required', 'bool');
$resolver->setAllowedTypes('shoeSize_required', 'bool');
$resolver->setAllowedTypes('height_choices', 'array');
$resolver->setAllowedTypes('weight_choices', 'array');
$resolver->setAllowedTypes('shoe_size_min', 'int');
$resolver->setAllowedTypes('shoe_size_max', 'int');
}
}
+16 -1
View File
@@ -88,7 +88,12 @@ class BookingEditParticipantType extends AbstractType
'required' => false,
'sanitize_html' => true,
], $getState('mobile')))
->add('bodyDimensions', BodyDimensionsType::class);
->add('bodyDimensions', BodyDimensionsType::class, [
'height_choices' => $options['height_choices'],
'weight_choices' => $options['weight_choices'],
'shoe_size_min' => $options['shoe_size_min'],
'shoe_size_max' => $options['shoe_size_max'],
]);
$commonChoiceFieldOptions = [
'required' => false,
@@ -371,7 +376,17 @@ class BookingEditParticipantType extends AbstractType
'applicant_id' => null,
// Booking DTO for field state provider (must be set by parent form)
'booking' => null,
// Body dimensions choices
'height_choices' => [],
'weight_choices' => [],
'shoe_size_min' => 36,
'shoe_size_max' => 48,
]);
$resolver->setAllowedTypes('height_choices', 'array');
$resolver->setAllowedTypes('weight_choices', 'array');
$resolver->setAllowedTypes('shoe_size_min', 'int');
$resolver->setAllowedTypes('shoe_size_max', 'int');
}
/**
+12
View File
@@ -252,6 +252,10 @@ class BookingParticipantType extends AbstractType
if ($this->fieldStateProvider->shouldIncludeField('bodyDimensions', $bookingDto, $participantIndex)) {
$form->add('bodyDimensions', BodyDimensionsType::class, [
'property_path' => 'participant',
'height_choices' => $form->getConfig()->getOption('height_choices'),
'weight_choices' => $form->getConfig()->getOption('weight_choices'),
'shoe_size_min' => $form->getConfig()->getOption('shoe_size_min'),
'shoe_size_max' => $form->getConfig()->getOption('shoe_size_max'),
]);
}
}
@@ -435,6 +439,10 @@ class BookingParticipantType extends AbstractType
'data_class' => ParticipantEditDto::class,
'selected_rooms' => [],
'booking_context' => null,
'height_choices' => [],
'weight_choices' => [],
'shoe_size_min' => 36,
'shoe_size_max' => 48,
'validation_groups' => function (FormInterface $form) {
/** @var ParticipantEditDto $data */
$data = $form->getData();
@@ -462,5 +470,9 @@ class BookingParticipantType extends AbstractType
$resolver->setAllowedTypes('selected_rooms', 'array');
$resolver->setAllowedTypes('booking_context', ['null', BookingDto::class]);
$resolver->setAllowedTypes('height_choices', 'array');
$resolver->setAllowedTypes('weight_choices', 'array');
$resolver->setAllowedTypes('shoe_size_min', 'int');
$resolver->setAllowedTypes('shoe_size_max', 'int');
}
}