I am currently creating a form that is supposed to retrieve the unmapped data to treat them before they are added to the database. How can I retrieve the unmapped data in the eventlistener? Here is my formtype code :
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('currentState', ChoiceType::class, [
'choices' => [
'Disponible' => 1,
'Hors service' => 2,
'Réservé' => 3
],
])
[...
->add('combination_reference', TextType::class, [
'label'=>'Référence de la déclinaison',
'mapped'=>false,
'attr'=>[
'class'=>'form-control mb-2',
'placeholder'=>'Référence de la déclinaison'
]
])
->addEventListener(FormEvents::SUBMIT, function(FormEvent $formEvent){
[retrieve unmapped data (combination_reference) here]
})
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => PhysicalProduct::class,
"allow_extra_fields" => true
]);
}
CodePudding user response:
You can access underlying unmapped data as follows
$form = $formEvent->getForm();
$combinationReference = $form->get('combination_reference')->getData();