title: Catchable Fatal Error in form event subscriber using Symfony 2.3
body: <p>After updating to Symfony 2.3 from 2.1, there is a strange message when I am trying to create a form :</p>
  
  <p>Catchable Fatal Error: Argument 1 passed to msgr\ProfileBundle\Form\EventListener\AddNameFieldSubscriber::preSetData() must be an instance of Symfony\Component\Form\Event\DataEvent, instance of Symfony\Component\Form\FormEvent given in /xxxxxx/aaas/src/msgr/ProfileBundle/Form/EventListener/AddNameFieldSubscriber.php line 29 </p>
  
  <p>These are the usual suspects :</p>
  
  <p>ProfileType.php</p>
  
  <pre><code>    &lt;?php
  
  namespace aaas\ProfileBundle\Form;
  
  use Doctrine\ORM\EntityRepository;
  
  use Symfony\Component\Form\FormFactoryInterface;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  use aaas\ProfileBundle\Form\EventListener\AddNameFieldSubscriber;
  
  
  class ProfileType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $subscriber = new AddNameFieldSubscriber($builder-&gt;getFormFactory());
          $builder-&gt;addEventSubscriber($subscriber);
          $builder
              -&gt;add('firstname')
              -&gt;add('lastname')
              -&gt;add('city')
              -&gt;add('country')
              -&gt;add('mobile')
              -&gt;add('description')
              -&gt;add('avatarFile')
              -&gt;add('website')
              -&gt;add('facebook')
              -&gt;add('twitter')
              -&gt;add('googlePlus')
              -&gt;add('gender', 'choice', array(
                  'choices'   =&gt; array('M' =&gt; 'man', 'F' =&gt; 'female'),
                  'required'  =&gt; true,
                  'empty_value' =&gt; 'choose your gender',
              ))
              ;        
      }
  
      //public function getParent()
      //{
      //    return 'form';
      //}
  
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'aaas\ProfileBundle\Entity\Profile'
          ));
      }
  
      public function getName()
      {
          return 'profile';
      }
  }
  </code></pre>
  
  <p>AddNameFieldSubscriber.php</p>
  
  <pre><code>&lt;?php
  // src/Acme/DemoBundle/Form/EventListener/AddNameFieldSubscriber.php
  namespace aaas\ProfileBundle\Form\EventListener;
  
  
  use Symfony\Component\Form\FormFactoryInterface;
  use Doctrine\ORM\EntityManager;
  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  use Symfony\Component\Form\FormEvents;
  use Symfony\Component\Form\Event\DataEvent;
  
  
  class AddNameFieldSubscriber implements EventSubscriberInterface
  {
      private $factory;
  
      public function __construct(FormFactoryInterface $factory)
      {
          $this-&gt;factory = $factory;
      }
  
      public static function getSubscribedEvents()
      {
          // Tells the dispatcher that we want to listen on the form.pre_set_data
          // event and that the preSetData method should be called.
          return array(FormEvents::PRE_SET_DATA =&gt; 'preSetData');
      }
  
      public function preSetData(DataEvent $event)
      {
          //$data = $event-&gt;getData();
          $form = $event-&gt;getForm();
  
          // During form creation setData() is called with null as an argument
          // by the FormBuilder constructor. We're only concerned with when
          // setData is called with an actual Entity object in it (whether new,
          // or fetched with Doctrine). This if statement let's us skip right
          // over the null condition.
          if (null === $data) {
              return;
          }
  
          // check if the product object is "new"
  
          if (!$data-&gt;getId()) {
              $form-&gt;add($this-&gt;factory-&gt;createNamed('username','text', array(
                                                     'auto_initialize' =&gt; false
                                                      )));
              $form-&gt;add($this-&gt;factory-&gt;createNamed('password','password'));
              $form-&gt;add($this-&gt;factory-&gt;createNamed('email','email'));
              $form-&gt;add($this-&gt;factory-&gt;createNamed('groups', 'entity',null, array(
                                                     'multiple' =&gt; false,
                                                     'class' =&gt; 'aaasProfileBundle:Group',
                                                     'query_builder' =&gt; function(EntityRepository $er) {
                                                                           return $er-&gt;createQueryBuilder('g')
                                                                                       -&gt;where('g.id != 1')
                                                                                       -&gt;andwhere('g.id != 2')
                                                                                       -&gt;andwhere('g.id != 3');
                                                        }
                                                    )));
          }
  
      }
  }
  </code></pre>
  
  <p>Unfortunately, I cannot find the root cause of the problem !</p>