title: How to add a calculated field in the FormEvents::PRE_SUBMIT Event
body: <p>In  my listener I need to access my entity when in the <code>FormEvents::PRE_SUBMIT</code> event. In <code>POST_SET_DATA</code> this is no problem, just use <code>$event-&gt;getData();</code>.</p>
  
  <p>So for the event listening to <code>POST_SET_DATA</code> I am fine with this code:</p>
  
  <pre><code>public function postSetData(FormEvent $event)
  {
      $form = $event-&gt;getForm();
      $day = $event-&gt;getData();
      $total = $this-&gt;dayManager-&gt;calculateTotal($day); // Passing a Day object, yay!
  
      $form-&gt;get('total')-&gt;setData($total);
  }
  </code></pre>
  
  <p>However in my method for the <code>PRE_SUBMIT</code> event.</p>
  
  <p><em>I need this function because on submitting, total is not calculated with the newly submitted data.</em></p>
  
  <pre><code>public function preSubmit(FormEvent $event)
  {
      $form = $event-&gt;getForm();
  
      // $day = $event-&gt;getData();
      // Raw array because $event-&gt;getData(); holds the old not updated Day object
      $day = $form-&gt;getData(); 
  
      // Ough! Had to create and call a seperate function on my dayManager that handles the raw event array
      $total = $this-&gt;dayManager-&gt;calculateTotalFromArray($event-&gt;getData());
  
      // Modify event data
      $data = $event-&gt;getData();
  
      // Ough(2)! Have to do nasty things to match the raw event array notation
      $totalArray = array( 
         'hour' =&gt; $total-&gt;format('G') . "", 
         'minute' =&gt; intval($total-&gt;format('i')) . ""
      );
      $data['total'] = $totalArray;
      $event-&gt;setData($data);
  }
  </code></pre>
  
  <p>As you can see, it works. However this is such a hackish way, I do not believe the pro's do it this way. Two things that go wrong here:</p>
  
  <ul>
  <li>Cannot work with entity <code>Day</code> object in the <code>preSubmit</code> function</li>
  <li>Have to create the <code>calculateTotalFromArray</code> function in the <code>dayManager</code></li>
  <li>Ugly code to match the raw event array in the <code>preSubmit</code> function </li>
  </ul>
  
  <p><strong>So the main question:</strong> how to get an updated <code>Day</code> object from the form in the <code>PRE_SUBMIT</code> form event.</p>