title: inject entitymanager in form type using service
body: <p>I use symfony2.7 and I have a problem when I want to inject the entitymanager into the formtype but I don't see that __construct() is called on my service, and injection doesn't work.
  I use a service to inject the entitymanager into my formtype like this.</p>
  
  <pre><code>public function createValeurChampNomenclatureAction(Request $request) {
          $em = $this-&gt;getDoctrine()-&gt;getManager();        
          $cgaValeurChampNomenclature = new CGAValeurchampnomenclature();
          $form = $this-&gt;createForm('espritApp_nomenclaturebundle_cgavaleurchampnomenclature', $CGAValeurChampNomenclature);
  ....
  </code></pre>
  
  <p>and in my formtype I have create my construct</p>
  
  <pre><code>     class CGAValeurChampNomenclatureType extends AbstractType
  {
  
    /**
   * @var EntityManager $entityManager Entity manager
   */
      private $em;
  
      /**
   * Constructor
   *
   * @param EntityManager $entityManager Entity manager
   */
      public function _construct(EntityManager $entityManager)
      {
          $this-&gt;em=$entityManager;
  
  
      }
  
      /**
       * @param FormBuilderInterface $builder
       * @param array $options
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
  
          $builder
              -&gt;add('cgatypenome','entity', array(
                      'class' =&gt; 'EspritAppNomenclatureBundle:CGATypenomenclature',
                      'property' =&gt; 'codeStr',
                      'multiple'  =&gt; false,
                      'required'    =&gt; true,
                      'attr'=&gt; array('class'=&gt;'form-control select2 codeStr'))
                      )
              -&gt;add('cgacodenomenclature','choice', array('required' =&gt; TRUE,
               'attr' =&gt; array('placeholder' =&gt; 'Code nomenclature','class'=&gt;'form-control select2 codeNomenclature')
                  ))
            -&gt;add('cgachamptypenome','choice', array('required' =&gt; TRUE,
               'attr' =&gt; array('placeholder' =&gt; 'Code Champ','class'=&gt;'form-control select2 codeChampNomenclature')
                  ))
           -&gt;add('chaCodeStr','text', array('required' =&gt; TRUE,
               'attr' =&gt; array('placeholder' =&gt; 'Champ code Str','class'=&gt;'form-control')
                  ))
                  -&gt;add('valeur','text', array('required' =&gt; TRUE,
               'attr' =&gt; array('placeholder' =&gt; 'valeur','class'=&gt;'form-control')
                  ));
  
  
          $formModif = function (FormInterface $form, $codeStr) 
          {             
              $listChampTypeNome = $this-&gt;em-&gt;getRepository('EspritAppNomenclatureBundle:CGAChamptypenomenclature')-&gt;getListChampTypeNomenclatureByCodeStr($codeStr);                       
              $listCodeNome = $this-&gt;em-&gt;getRepository('EspritAppNomenclatureBundle:CGACodenomenclature')-&gt;getListCodeNomenclatureByCodeStr($codeStr);
  
               if ($listChampTypeNome) {
                  $ChampsTypeNome = array();
                  foreach($listChampTypeNome as $ChampTypeNome) {
                      $ChampsTypeNome[] = $ChampTypeNome-&gt;getCodeChamp();                   
                  }
              } else {
                  $ChampsTypeNome = null;
              }
  
  
               if ($listCodeNome) {
                  $CodesNome = array();
                  foreach($listCodeNome as $CodeNome) {
                      $CodesNome[] = $CodeNome-&gt;getCodeNome();                   
                  }
              } else {
                  $CodesNome = null;
              }
  
  
              $form-&gt;add('cgacodenomenclature','choice', array('required' =&gt; TRUE,
               'attr' =&gt; array('placeholder' =&gt; 'Code nomenclature','class'=&gt;'form-control select2 codeNomenclature'),'choices' =&gt;$ChampsTypeNome)
                  )
                  -&gt;add('cgachamptypenome','choice', array('required' =&gt; TRUE,
               'attr' =&gt; array('placeholder' =&gt; 'Code Champ','class'=&gt;'form-control select2 codeChampNomenclature'),'choices'=&gt;$CodesNome)
                  );
          };
  
          $builder-&gt;get('cgacodenomenclature')-&gt;addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($formModif){
              $formModif($event-&gt;getForm()-&gt;getParent(),$event-&gt;getForm()-&gt;getData());
          });
  
  
  
  
      }
  
      /**
       * @param OptionsResolverInterface $resolver
       */
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'EspritApp\NomenclatureBundle\Entity\CGAValeurchampnomenclature'
          ));
      }
  
      /**
       * @return string
       */
      public function getName()
      {
          return 'espritApp_nomenclaturebundle_cgavaleurchampnomenclature';
      }
  }
  </code></pre>
  
  <p>and this my service in services.yml</p>
  
  <pre><code> app.form.type.cgavaleurchampnome:
          class:  EspritApp\NomenclatureBundle\Form\CGAValeurChampNomenclatureType
          tags:
              - { name: form.type, alias: espritApp_nomenclaturebundle_cgavaleurchampnomenclature }
          arguments: [@doctrine.orm.entity_manager]
  </code></pre>
  
  <p>the problem that I got this Error: </p>
  
  <blockquote>
    <p>Call to a member function getRepository() on a non-object</p>
  </blockquote>