I am trying to do a dynamic Form on two choiceList and i've tried to follow the documentation about SYmfony: http://symfony.com/doc/current/form/dynamic_form_modification.html#dynamic-generation-for-submitted-forms but the are using two entities and i have to work with choiceList Can anyone help me about that here is my UserTYpe:
$
builder
->add('at', ChoiceType::class, array(
'label' => ' ',
'choices' =>array(
"42consulting.fr" => "42consulting.fr",
"42consulting.lu" => "42consulting.lu",
"42mediatvcom.fr" => "42mediatvcom.fr",
"42consulting.ma" => "42consulting.ma",
"42consulting.nl" => "42consulting.nl",
),
'attr' => array(
'class' => 'form-control',
'placeholder' => 'service',
),
)
);
$formModifier = function (FormInterface $form, User $at= null) {
$services = null === $at ? array() :$at->getService();
$form->add('service', ChoiceType::class, array(
'label' => 'Service',
'choices' => array(
"42Consulting Paris" => "Saint-Mandé",
"42Consulting Lux" => "Luxembourg",
"42MediaTelecom" => "Issy-Les-Moulineaux",
"42Consulting Maroc" => "Casablanca"
),
'attr' => array(
'class' => 'form-control service',
'placeholder' => 'service',
),
)
);
};
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) use ($formModifier) {
$data = $event->getData();
$formModifier($event->getForm(), $data->getAt());
}
);
$builder->get('at')->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) use ($formModifier) {
$at = $event->getForm()->getData();
$formModifier($event->getForm()->getParent(), $at);
}
);
and the error that i'm getting is : Type error: Argument 2 passed to BackBundle\Form\UserType::BackBundle\Form{closure}() must be an instance of BackBundle\Entity\User, string given, called in /home/work/Sites/backoffice-ad/src/BackBundle/Form/UserType.php on line 263 (on this line: $formModifier($event->getForm()->getParent(), $at);)