wip: refactor
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Form;
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\Form\Model\BookingEditDto;
|
||||
use App\Form\ParticipantFieldHandler\ParticipantFieldHandlerRegistry;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -14,9 +15,19 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class BookingEditType extends AbstractType
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ParticipantFieldHandlerRegistry $participantFieldHandlerRegistry,
|
||||
) {}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
$builder
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'onPreSetData'])
|
||||
->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'onPreSubmit']);
|
||||
}
|
||||
|
||||
public function onPreSetData(FormEvent $event): void
|
||||
{
|
||||
/** @var BookingEditDto $data */
|
||||
$data = $event->getData();
|
||||
$form = $event->getForm();
|
||||
@@ -44,7 +55,14 @@ class BookingEditType extends AbstractType
|
||||
'allow_add' => false,
|
||||
'allow_delete' => false,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function onPreSubmit(FormEvent $event): void
|
||||
{
|
||||
$form = $event->getForm();
|
||||
$submittedData = $event->getData();
|
||||
$bookingDto = $form->getData();
|
||||
$this->participantFieldHandlerRegistry->processFields($submittedData, $bookingDto);
|
||||
}
|
||||
|
||||
private function mergeSelectableServices(BookingEditDto $data, string|array $subType): array
|
||||
|
||||
Reference in New Issue
Block a user