title: Symfony2: Entity form field with empty value
body: <p>i have a form definition which uses the so-far great field type <code>entity</code>. With the option <code>query_builder</code> I select my values and the are displayed.</p>
  
  <p>The sad part is, I am required to display a <code>null</code> default value, like <code>all</code> (it's a filter form). I don't like the <code>choices</code> option of <code>entity</code> because I have database values and a <code>FormType</code> shouldn't query the database.</p>
  
  <p>My approach so far was to implement a custom field type which extends <code>entity</code> and adds a null entry to the top of the list. The field type is loaded and used but unfortunately the dummy value is not displayed.</p>
  
  <p>The field definition:</p>
  
  <pre><code>$builder-&gt;add('machine', 'first_null_entity', [
      'label' =&gt; 'label.machine',
      'class' =&gt; Machine::ident(),
      'query_builder' =&gt; function (EntityRepository $repo)
      {
          return $repo-&gt;createQueryBuilder('m')
              -&gt;where('m.mandator = :mandator')
              -&gt;setParameter('mandator', $this-&gt;mandator)
              -&gt;orderBy('m.name', 'ASC');
      }
  ]);
  </code></pre>
  
  <p>The form type definition:</p>
  
  <pre><code>class FirstNullEntityType extends AbstractType
  {
  
      /**
       * @var unknown
       */
      private $doctrine;
  
      public function __construct(ContainerInterface $container)
      {
          $this-&gt;doctrine = $container-&gt;get('doctrine');
      }
  
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setRequired('query_builder');
          $resolver-&gt;setRequired('class');
      }
  
      public function buildView(FormView $view, FormInterface $form, array $options)
      {
          $class = $options['class'];
          $repo = $this-&gt;doctrine-&gt;getRepository($class);
  
          $builder = $options['query_builder']($repo);
          $entities = $builder-&gt;getQuery()-&gt;execute();
  
          // add dummy entry to start of array
          if($entities) {
              $dummy = new \stdClass();
              $dummy-&gt;__toString = function() {
                  return '';
              };
              array_unshift($entities, $dummy);
          }
  
          $options['choices'] = $entities;
      }
  
      public function getName()
      {
          return 'first_null_entity';
      }
  
      public function getParent()
      {
          return 'entity';
      }
  }
  </code></pre>