title: Symfony 3.3 Form - EntityType field does not select option
body: <p>For some unknown reason, the EntityType form field will not display the selected option on submit, even though the name of the column matches and data passes.  </p>
  
  <p>I've created a form that I'm using to select some values that will filter a list of products.</p>
  
  <pre><code>&lt;?php namespace AppBundle\Filter;
  
  use AppBundle\Entity\ProductCategory; 
  use AppBundle\Repository\ProductCategoryRepository; 
  use Symfony\Bridge\Doctrine\Form\Type\EntityType; 
  use Symfony\Component\Form\AbstractType; 
  use Symfony\Component\Form\FormBuilderInterface;
  
  class ProductFilterType extends AbstractType {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('id', null, [
                  'required'   =&gt; false,
                  'label'      =&gt; 'SKU'
              ])
              -&gt;add('productCategory', EntityType::class,
                  array(
                      'class' =&gt; ProductCategory::class,
                      'choice_label' =&gt; 'name',
                      'choice_value' =&gt; 'id',
                      'placeholder' =&gt; '',
                      'label_attr' =&gt; array('title' =&gt; 'Category for this product'),
                      'query_builder' =&gt; function (ProductCategoryRepository $v) {
                          return $v-&gt;createQueryBuilder('v')
                              -&gt;orderBy('v.name',' ASC');
                      }
                  ))
              -&gt;add('name', null, [
                  'required'   =&gt; false,
              ])
              -&gt;add('description', null, [
                  'required'   =&gt; false,
              ])
  
  
          ;
      }
  
  
      /**
       * {@inheritdoc}
       */
      public function getBlockPrefix()
      {
          return 'app_bundle_product_filter_type';
      } }
  </code></pre>
  
  <p>The form renders as expected, and it submits a post to the same URL, which filters based on the value received from the request.  </p>
  
  <p>That works ok.</p>
  
  <p>However, when the form is re-rendered, the option that was selected before the form filter submission is no longer selected.  All other inputs are repopulating.</p>
  
  <p><a href="https://i.stack.imgur.com/Xoy11.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xoy11.png" alt="enter image description here"></a></p>
  
  <p>I did notice that when I'm working with a form that is bound to an Entity (ie:  Editting and saving the entity) and using the ConfigureOptions method to set the data class, that the EntityType form field works as expected.  However, I need it to work in this case where the overall form is not bound to an Entity.</p>
  
  <p>EDIT:
  Doing these steps worked for me...but it seems a bit odd.</p>
  
  <p>Injected entity manager into the form constructor:</p>
  
  <pre><code>public $em;
  
  public function __construct(EntityManager $em) {
      $this-&gt;em = $em;
  }
  </code></pre>
  
  <p>Then updated the EntityType form field to get the object based on the array value:</p>
  
  <pre><code>-&gt;add('productCategory', EntityType::class,
              array(
                  'class' =&gt; ProductCategory::class,
                  'choice_label' =&gt; 'name',
                  'choice_value' =&gt; 'id',
                  'placeholder' =&gt; '',
                  'label_attr' =&gt; array('title' =&gt; 'Category for this product'),
                  'data' =&gt;  $this-&gt;em-&gt;getReference("AppBundle:ProductCategory",
                      isset($options['data']['productCategory']) ? $options['data']['productCategory'] : 0),
                  'query_builder' =&gt; function (ProductCategoryRepository $v) {
                      return $v-&gt;createQueryBuilder('v')
                          -&gt;orderBy('v.name',' ASC');
                  }
              ))
  </code></pre>
  
  <p>...</p>