title: Passing data to buildForm() in Symfony 3.3
body: <p>i'm trying to pass current authenticated user to buildForm for the pass couple of hours, i searched google ... nothing worked
  the error i'm getting is</p>
  
  <blockquote>
    <p>The form's view data is expected to be an instance of class AppBundle\Entity\AdsList, but is a(n) array. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms a(n) array to an instance of AppBundle\Entity\AdsList.</p>
  </blockquote>
  
  <p>on <code>-&gt;getForm();</code></p>
  
  <p>i have to ideea what to do ... a view transformer ... ( <a href="https://symfony.com/doc/current/form/data_transformers.html" rel="nofollow noreferrer">https://symfony.com/doc/current/form/data_transformers.html</a> )</p>
  
  <p>but i only have an integer ...</p>
  
  <p>i also want to generate unique slugs from the content ( final version wont have a title field ) if you have a good example :)</p>
  
  <p>thanks in advance :)</p>
  
  <p><strong>AgencyController.php</strong></p>
  
  <pre><code>/**
   * @Route("/agency/post", name="agency_post")
   */
  public function agencyNewAd(Request $request)
  {
     //  $agency = $this-&gt;get('security.token_storage')-&gt;getToken()-&gt;getUser(); ( this didn't worked .. )
      $form = $this-&gt;createForm(AgencyNewAdType::class, array(
          'postedBy' =&gt; $this-&gt;getUser(),
      ));
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
  
          $ad = $form-&gt;getData();
  
          // save the task to the database
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $em-&gt;persist($ad);
          $em-&gt;flush();
          // return new Response('Saved new Post with id ' . $ad-&gt;getId());
          return $this-&gt;redirectToRoute('agency_admin');
      }
      return $this-&gt;render('agency/new_ad.html.twig', [
          'adForm' =&gt; $form-&gt;createView()
      ]);
  }
  </code></pre>
  
  <p><strong>AgencyNewAdType.php</strong></p>
  
  <pre><code>class AgencyNewAdType extends AbstractType
  {
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      // https://stackoverflow.com/questions/36905490/how-to-pass-parameter-to-formtype-constructor-from-controller
      $builder
          -&gt;add('title', TextType::class)
          -&gt;add('content', TextareaType::class)
          -&gt;add('category', EntityType::class, array(
              // query choices from Category.Name
              'class' =&gt; 'AppBundle:CategoryAd',
              'choice_label' =&gt; 'name',
          ))
          -&gt;add('postedAt', DateType::class)
          -&gt;add('postedBy',HiddenType::class, array(
              'data' =&gt; $options['postedBy']
          ))
          -&gt;add('save', SubmitType::class, array('label' =&gt; 'Create Post'))
          -&gt;getForm();
  
  }
  public function configureOptions(OptionsResolver $resolver)
     {
      $resolver-&gt;setDefaults(array(
          'postedBy' =&gt; null,
          'data_class' =&gt; 'AppBundle\Entity\AdsList',
      ));
     }
  }
  </code></pre>