wip: refactor forms
This commit is contained in:
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class BodyDimensionsType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('height', ChoiceType::class, [
|
||||||
|
'label' => 'Körpergröße',
|
||||||
|
'required' => false,
|
||||||
|
'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+',
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->add('shoeSize', ChoiceType::class, [
|
||||||
|
'label' => 'Schuhgröße',
|
||||||
|
'required' => false,
|
||||||
|
'expanded' => false,
|
||||||
|
'multiple' => false,
|
||||||
|
'placeholder' => 'Keine Angabe',
|
||||||
|
'choices' => array_combine(range(36, 48), range(36, 48)),
|
||||||
|
])
|
||||||
|
->add('weight', ChoiceType::class, [
|
||||||
|
'label' => 'Gewicht',
|
||||||
|
'required' => false,
|
||||||
|
'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+',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'inherit_data' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,6 +65,7 @@ class BookingCreateParticipantType extends AbstractType
|
|||||||
'required' => false,
|
'required' => false,
|
||||||
'clean_xss' => true,
|
'clean_xss' => true,
|
||||||
])
|
])
|
||||||
|
->add('bodyDimensions', BodyDimensionsType::class)
|
||||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
|
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
|
||||||
/** @var ParticipantDto|null $participantData */
|
/** @var ParticipantDto|null $participantData */
|
||||||
$participantData = $event->getData();
|
$participantData = $event->getData();
|
||||||
@@ -95,8 +96,7 @@ class BookingCreateParticipantType extends AbstractType
|
|||||||
'placeholder' => 'Bitte wählen',
|
'placeholder' => 'Bitte wählen',
|
||||||
'choice_loader' => $choiceLoader,
|
'choice_loader' => $choiceLoader,
|
||||||
]);
|
]);
|
||||||
})
|
});
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver): void
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ class BookingCreateStep2Type extends AbstractType
|
|||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'onPreSetData'])
|
->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'onPreSetData'])
|
||||||
->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'onPreSubmit'])
|
->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'onPreSubmit']);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +59,7 @@ class BookingCreateStep2Type extends AbstractType
|
|||||||
if (isset($participantData['assignedRoomId']) && isset($bookingDto->participants[$index])) {
|
if (isset($participantData['assignedRoomId']) && isset($bookingDto->participants[$index])) {
|
||||||
$roomId = $participantData['assignedRoomId'];
|
$roomId = $participantData['assignedRoomId'];
|
||||||
// An unselected choice submits an empty string.
|
// An unselected choice submits an empty string.
|
||||||
$bookingDto->participants[$index]->assignedRoomId = '' === $roomId ? null : (int) $roomId;
|
$bookingDto->participants[$index]->assignedRoomId = empty($roomId) ? null : (int) $roomId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +76,6 @@ class BookingCreateStep2Type extends AbstractType
|
|||||||
'entry_type' => BookingCreateParticipantType::class,
|
'entry_type' => BookingCreateParticipantType::class,
|
||||||
'allow_add' => false,
|
'allow_add' => false,
|
||||||
'allow_delete' => false,
|
'allow_delete' => false,
|
||||||
'by_reference' => false,
|
|
||||||
'entry_options' => [
|
'entry_options' => [
|
||||||
'selected_rooms' => $data->getSelectedRooms(),
|
'selected_rooms' => $data->getSelectedRooms(),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -99,45 +99,7 @@ class BookingEditParticipantType extends AbstractType
|
|||||||
],
|
],
|
||||||
'clean_xss' => true,
|
'clean_xss' => true,
|
||||||
])
|
])
|
||||||
->add('height', ChoiceType::class, [
|
->add('bodyDimensions', BodyDimensionsType::class);
|
||||||
'label' => 'Körpergröße',
|
|
||||||
'required' => false,
|
|
||||||
'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+',
|
|
||||||
],
|
|
||||||
])
|
|
||||||
->add('shoeSize', ChoiceType::class, [
|
|
||||||
'label' => 'Schuhgröße',
|
|
||||||
'required' => false,
|
|
||||||
'expanded' => false,
|
|
||||||
'multiple' => false,
|
|
||||||
'placeholder' => 'Keine Angabe',
|
|
||||||
'choices' => array_combine(range(36, 48), range(36, 48)),
|
|
||||||
])
|
|
||||||
->add('weight', ChoiceType::class, [
|
|
||||||
'label' => 'Gewicht',
|
|
||||||
'required' => false,
|
|
||||||
'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+',
|
|
||||||
],
|
|
||||||
])
|
|
||||||
;
|
|
||||||
|
|
||||||
$commonChoiceFieldOptions = [
|
$commonChoiceFieldOptions = [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
@@ -278,8 +240,7 @@ class BookingEditParticipantType extends AbstractType
|
|||||||
'multiple' => false,
|
'multiple' => false,
|
||||||
'choices' => $options['selectable_transportation_services_fro'],
|
'choices' => $options['selectable_transportation_services_fro'],
|
||||||
'choice_attr' => $transportationChoiceAttributes,
|
'choice_attr' => $transportationChoiceAttributes,
|
||||||
])
|
]);
|
||||||
;
|
|
||||||
|
|
||||||
// Pickup
|
// Pickup
|
||||||
$form->add('pickup', ChoiceType::class, [
|
$form->add('pickup', ChoiceType::class, [
|
||||||
@@ -296,7 +257,7 @@ class BookingEditParticipantType extends AbstractType
|
|||||||
$pickupLabel = $pickup->city;
|
$pickupLabel = $pickup->city;
|
||||||
|
|
||||||
if (null !== $pickup->street) {
|
if (null !== $pickup->street) {
|
||||||
$pickupLabel .= ' ('.$pickup->street.')';
|
$pickupLabel .= ' (' . $pickup->street . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
$price = $pickup->price;
|
$price = $pickup->price;
|
||||||
@@ -324,46 +285,46 @@ class BookingEditParticipantType extends AbstractType
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
})
|
})
|
||||||
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) {
|
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) {
|
||||||
$data = $event->getData();
|
$data = $event->getData();
|
||||||
$form = $event->getForm();
|
$form = $event->getForm();
|
||||||
|
|
||||||
// skip processing for canceled participants
|
// skip processing for canceled participants
|
||||||
if ('F' !== $form->getData()->status) {
|
if ('F' !== $form->getData()->status) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
$transportationId = $data['transportationServiceTo'] ?? null;
|
|
||||||
$transportation = $options['travel']->pickups[$transportationId] ?? null;
|
|
||||||
|
|
||||||
if (null !== $transportation && 'PKW' === $transportation->subType) {
|
|
||||||
$form->remove('pickup');
|
|
||||||
unset($data['pickup']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// forcibly select mandatory services that potentially have been disabled in PRE_SET_DATA
|
|
||||||
$mandatoryServices = array_filter($options['selectable_services'], function (Service $service) use ($form) {
|
|
||||||
$participantIndex = $form->getData()->index;
|
|
||||||
|
|
||||||
return true === $service->mandatory
|
|
||||||
|| (Constants::SOURCE_BOOKING === $service->source && in_array($participantIndex, $service->mapping));
|
|
||||||
});
|
|
||||||
|
|
||||||
if (0 < count($mandatoryServices)) {
|
|
||||||
if (false === isset($data['additionalServices'])) {
|
|
||||||
$data['additionalServices'] = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$mandatoryServiceIds = array_map(function (Service $service) {
|
$transportationId = $data['transportationServiceTo'] ?? null;
|
||||||
return $service->id;
|
$transportation = $options['travel']->pickups[$transportationId] ?? null;
|
||||||
}, $mandatoryServices);
|
|
||||||
|
|
||||||
$allServiceIds = [...$mandatoryServiceIds, ...$data['additionalServices']];
|
if (null !== $transportation && 'PKW' === $transportation->subType) {
|
||||||
$data['additionalServices'] = array_unique($allServiceIds);
|
$form->remove('pickup');
|
||||||
}
|
unset($data['pickup']);
|
||||||
|
}
|
||||||
|
|
||||||
$event->setData($data);
|
// forcibly select mandatory services that potentially have been disabled in PRE_SET_DATA
|
||||||
});
|
$mandatoryServices = array_filter($options['selectable_services'], function (Service $service) use ($form) {
|
||||||
|
$participantIndex = $form->getData()->index;
|
||||||
|
|
||||||
|
return true === $service->mandatory
|
||||||
|
|| (Constants::SOURCE_BOOKING === $service->source && in_array($participantIndex, $service->mapping));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (0 < count($mandatoryServices)) {
|
||||||
|
if (false === isset($data['additionalServices'])) {
|
||||||
|
$data['additionalServices'] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$mandatoryServiceIds = array_map(function (Service $service) {
|
||||||
|
return $service->id;
|
||||||
|
}, $mandatoryServices);
|
||||||
|
|
||||||
|
$allServiceIds = [...$mandatoryServiceIds, ...$data['additionalServices']];
|
||||||
|
$data['additionalServices'] = array_unique($allServiceIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
$event->setData($data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver): void
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class BookingEditType extends AbstractType
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function mergeSelectableServices(BookingEditDto $data, mixed $subType): array
|
private function mergeSelectableServices(BookingEditDto $data, string|array $subType): array
|
||||||
{
|
{
|
||||||
// combine selectable services from travel data with additional services
|
// combine selectable services from travel data with additional services
|
||||||
// from booking data
|
// from booking data
|
||||||
|
|||||||
@@ -27,6 +27,11 @@
|
|||||||
{{ form_row(participant.email) }}
|
{{ form_row(participant.email) }}
|
||||||
{{ form_row(participant.mobile) }}
|
{{ form_row(participant.mobile) }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="grid grid-cols-2 gap-4">
|
||||||
|
{{ form_row(participant.bodyDimensions.height) }}
|
||||||
|
{{ form_row(participant.bodyDimensions.shoeSize) }}
|
||||||
|
{{ form_row(participant.bodyDimensions.weight) }}
|
||||||
|
</div>
|
||||||
<div class="grid grid-cols-1 gap-4 pt-4">
|
<div class="grid grid-cols-1 gap-4 pt-4">
|
||||||
{# hx-swap="none" tells HTMX not to do a normal swap, as OOB will handle it #}
|
{# hx-swap="none" tells HTMX not to do a normal swap, as OOB will handle it #}
|
||||||
{{ form_row(participant.assignedRoomId, {
|
{{ form_row(participant.assignedRoomId, {
|
||||||
|
|||||||
@@ -175,9 +175,9 @@
|
|||||||
{{ form_row(child.mobile) }}
|
{{ form_row(child.mobile) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-x-8 gap-y-4">
|
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-x-8 gap-y-4">
|
||||||
{{ form_row(child.height) }}
|
{{ form_row(child.bodyDimensions.height) }}
|
||||||
{{ form_row(child.shoeSize) }}
|
{{ form_row(child.bodyDimensions.shoeSize) }}
|
||||||
{{ form_row(child.weight) }}
|
{{ form_row(child.bodyDimensions.weight) }}
|
||||||
</div>
|
</div>
|
||||||
{% if not travelData.participantDataMutable %}
|
{% if not travelData.participantDataMutable %}
|
||||||
<div class="absolute top-0 left-0 inset-0 cursor-not-allowed"></div>
|
<div class="absolute top-0 left-0 inset-0 cursor-not-allowed"></div>
|
||||||
|
|||||||
Reference in New Issue
Block a user