3
votes

I have a form type that incorporates another form type.

I've added an event-listener to the sub-form but the listener is never executed.

The first Form Type :

class AFormType extends AbstractType {

   public function buildForm(FormBuilderInterface $builder, array $options) {
       $builder
               ->add('aSubFormType', new SubFormType());
   }
//[...]
}

The second Form Type :

class SubFormType extends AbstractType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
    $builder->add("metier", "text");

    $builder->addEventListener(
        \Symfony\Component\Form\FormEvents::PRE_SET_DATA,
        function(\Symfony\Component\Form\FormEvent $event){
        // Some Stuff never executed
    });        
    }
}

I don't know if this behaviour is the right or if this is a bug? And how I can use EventListner in sub-form ?

Thanks

1
Your code as posted looks correct. I would use 'use' statements like the example:symfony.com/doc/current/cookbook/form/…. I assume the form shows up correctly? Add a die statement just to make sure the function is never being called.Cerad
you guess right. the form show up correctly, but the event is never call. I've add a die statement, like you ask. The page and the form show up correctly. I tried to figure out what happened in the symfony2 event system. And i don't know why the Symfony\Component\EventDispatcher\EventDispatcher loose my event.Waldo
I have the same probleme. It seems, symfony doesn't search for events/Data transformation on children formType (after digging in the form class)Chopchop
So, we must maybe open a bug ticket? I don't know if this behaviour in wanted or if it's a bug?Waldo

1 Answers

0
votes

So this is a bug.

Like Stoph has written here : https://github.com/symfony/symfony/issues/10399#issuecomment-37171979

The PRE_SET_DATA not being triggered for virtual forms is already known. Closing as duplicate of #8253