title: Symfony2 Forms - Dependent entity fields
body: <p>Relating to a cars application, I have a form where the user can choose brand and model ; the aim is that the model depends on the brand. For example, when you choose "Brand A", then only models related to brand A are displayed. </p>
  
  <p>For now, I am already blocked on the initial form (where no data is set) ; there is a default brand displayed, and I would like models relative to this brand being displayed.</p>
  
  <p>I followed some tutorials to add an event subscriber, but I can't make it works ; I am unable to get brand's field value into my subscriber... I tryed to get the Brand entity, but logically it is empty (because the form has not been submitted).</p>
  
  <p>Anybody has an idea ?</p>
  
  <p>FormType :</p>
  
  <pre><code>public function buildForm( FormBuilderInterface $builder, array $options ) {
  
      $builder-&gt;add( 'brand', 'entity', array(
          'class' =&gt; 'MyBundle:Brand',
          'property' =&gt; 'name',
      ));
  
      $builder-&gt;add( 'model', 'entity', array(
          'class' =&gt; 'MyBundle:Model',
          'property' =&gt; 'name',   
      ));
  
  
      /* Add event for the first model choices */
      $builder-&gt;addEventSubscriber( new ModelChoicesSubscriber() );
  }
  </code></pre>
  
  <p>FormSubscriber : </p>
  
  <pre><code>class ModelChoicesSubscriber implements EventSubscriberInterface {
  
      public static function getSubscribedEvents() {
  
          return array( FormEvents::PRE_SET_DATA =&gt; 'preSetData' );
      }
  
      public function preSetData( FormEvent $event ) {
          $data = $event-&gt;getData();
          $form = $event-&gt;getForm();
  
          if( $data == null ) {
              return;
          }
  
          $brand = $form-&gt;get( 'brand' );
      }
  
  }
  </code></pre>