title: Symfony form Event Listener for collection fields
body: <p>I use event listener for change data dynamically based on user inputs. Each time I use <code>PRE_SET_DATA</code> and <code>PRE_SUBMIT</code> events for set data and fields choices. Here is the simple example of actions from <code>PRE_SUBMIT</code>:    </p>
  
  <pre><code>// Pre set share locations by share day
  if (array_key_exists('shares', $data)) {
      foreach ($data['shares'] as $key =&gt; $share) {
          if ($share['pickUpDay'] !== null) {
              $shareType = $form-&gt;get('shares')-&gt;get($key);
  
              $locations = $this-&gt;em-&gt;getRepository('AppBundle:Member\Location')-&gt;getLocationsByDay($client, $data['shares'][$key]['pickUpDay']);
              $this-&gt;addLocationField($shareType, $locations);
           }
       }
   }
  </code></pre>
  
  <p>Not matter what inside <code>addLocationField</code> function, it works right.  </p>
  
  <p>When I do <code>$form-&gt;get('shares')</code>, its my collection field, then I need to <code>-&gt;get(child)</code> of this collection and set fields data and choices straight to this child. By when I add collection dynamically, Symfony shows error: </p>
  
  <blockquote>
    <p>Child "n" does not exist. </p>
  </blockquote>
  
  <p>And this problem happens only when I try to get data of new collection that was added dynamically. So I can't get to a collection field and change choices, so I receive error that my new value is not in a choice list. </p>
  
  <p>Interesting that <code>$data['shares']</code> have all data for new collection elements, but <code>$form-&gt;get('shares')</code> haven`t:</p>
  
  <pre><code>var_dump(count($event-&gt;getData()['shares'])) - return 1;  
  var_dump(count($form-&gt;get('shares'))) - return 0;
  </code></pre>
  
  <p>Is that mean that my <code>PRE_SUBMIT</code> works before Symfony collection functionality happen?</p>
  
  <p>Someone know how to fix it?</p>