title: Adding choices dynamically using EventSubscriber to Symfony2 form
body: <p>I am trying to set the choices for a form select dynamically since the choices come from a service call. However, when the form renders in the view, the choices are not there. </p>
  
  <p>I'm doing the following in the <code>FormType</code></p>
  
  <pre><code>&lt;?php
  
  namespace My\Form\Customer;
  
  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  
  class ItemReturnRequestForm extends AbstractType
  {
  
      /**
       * @var EventSubscriberInterface
       */
      protected $reasonsSubscriber;
  
      /**
       * Returns the name of this type.
       *
       * @return string The name of this type
       */
      public function getName()
      {
          return 'item_return_request';
      }
  
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('reason', 'choice', [
              'label' =&gt; 'order.returns.reason_for_return',
              'required' =&gt; true,
              'multiple' =&gt; false,
              'expanded' =&gt; false,
              'placeholder' =&gt; 'order.returns.reasons.empty',
              'empty_data' =&gt; null,
          ]);
  
          $builder-&gt;addEventSubscriber($this-&gt;reasonsSubscriber);
      }
  
      /**
       * @param EventSubscriberInterface $reasonsSubscriber
       */
      public function setReasonsSubscriber(EventSubscriberInterface $reasonsSubscriber)
      {
          $this-&gt;reasonsSubscriber = $reasonsSubscriber;
      }
  }
  </code></pre>
  
  <p>The <code>FormType</code> has a service definition which injects the <code>EventSubscriber</code> instance since that is also a service definition with it's own dependencies.</p>
  
  <p>The <code>EventSubscrbier</code> looks like</p>
  
  <pre><code>&lt;?php
  
  namespace My\Form\EventSubscriber;
  
  use My\Customer\ItemReturnAware;
  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  use Symfony\Component\Form\FormEvent;
  use Symfony\Component\Form\FormEvents;
  
  class ReturnReasonEventSubscriber implements EventSubscriberInterface
  {
      use ItemReturnAware;
  
      public static function getSubscribedEvents()
      {
          return [
              FormEvents::PRE_SET_DATA =&gt; 'getReturnReasons',
          ];
      }
  
      public function getReturnReasons(FormEvent $event)
      {
          $form = $event-&gt;getForm();
  
          if ($form-&gt;has('reason')) {
              $options = $form-&gt;get('reason')-&gt;getConfig()-&gt;getOptions();
              $options['choices'] = $this-&gt;itemReturnService-&gt;getReasons();
  
              $form-&gt;add('reason', 'choice', $options);
          }
      }
  }
  </code></pre>
  
  <p>Everything seems to work fine up until this point. Using XDEBUG I can see that the <code>EventSubscriber</code> is being triggered. The service call sets <code>$option['choices']</code> to the expected array value &amp; the field is added successfully.</p>
  
  <p>However, when the form gets rendered. it's as if the <code>EventSubscriber</code> had never been called.</p>
  
  <p>If it makes a difference, the options array is an un-ordered numeric list. </p>
  
  <p>i.e.</p>
  
  <pre><code>$options = [
      10 =&gt; 'First choice',
      15 =&gt; 'Second choice',
      20 =&gt; 'Third choice',
  ];
  </code></pre>
  
  <p>Any ideas?</p>