title: Symfony2, Sonata, FormMapper, add hidden field to be handled in PrePersist/PreUpdate
body: <p>I actually did some tricks so i could be able to persist a user if its ID is passed by an url parameter. (Custom action from user list).</p>
  
  <p>/admin/se/api/bundle/create?<strong>user=7</strong></p>
  
  <p>I actually could not find how to send the user entity returned by a findByOne(array('id' => $user_id)) so i guess i'll need to pass the $user_id through a hidden field and handle its value in a PrePersist</p>
  
  <p>Otherwise passing the id that way </p>
  
  <pre><code>-&gt;add('user', 'hidden', array('data' =&gt; $user_id))
  </code></pre>
  
  <p>will return an error : </p>
  
  <blockquote>
    <p>This value is not valid.   </p>
    
    <p>Symfony\Component\Validator\ConstraintViolation
    Object(Symfony\Component\Form\Form).children[user] = 7</p>
    
    <p>Caused by:</p>
    
    <p>Symfony\Component\Form\Exception\TransformationFailedException
    Compound forms expect an array or NULL on submission.</p>
  </blockquote>
  
  <p>This is my first attempt that is <strong>not</strong> working :</p>
  
  <pre><code>$container = $this-&gt;getConfigurationPool()-&gt;getContainer();
  
  $request = $container-&gt;get('request');
  
  $user_id = $request-&gt;get('user');
  
  if(!empty($user_id)){
  
      $em = $this-&gt;getModelManager()-&gt;getEntityManager($this-&gt;getClass());
  
      $user = $em-&gt;getRepository('ApiBundle:User')-&gt;findOneBy(array('id' =&gt; $user_id));
  
      if($user){
  
          $formMapper
              -&gt;with('User', array('description' =&gt; '&lt;strong&gt;User : &lt;/strong&gt;'.$user-&gt;getDisplayName()))
                  -&gt;add('user', 'hidden', array('data' =&gt; $user_id))
                  // this of course doesn't work as explained above. How can i have my own hidden input not related to any property
              -&gt;end();
  
      }
  </code></pre>
  
  <p>So how would i do that? Any better solution is welcomed.</p>