title: Create form in Controller using Sonata field type
body: <p>In Symfony admin, I have a form, where the second field type depends on the <code>ChoiceField</code> value selected. The second field can be of Symfony <strong>Url</strong> field type or sonata provided <strong>sonata_type_model_list</strong> field type.</p>
  <p>I have created an ajax request to My Bundle Controller to return the form, which contains the needed field.</p>
  <pre><code>&gt; /src/MyBundle/Controller/MyController.php
  
  namespace MyBundle\Controller
  
  use Sonata\AdminBundle\Controller\CRUDController;
  use Symfony\Component\HttpFoundation\Request;
  use Doctrine\ORM\Mapping\ClassMetadataInfo;
  use Sonata\AdminBundle\Form\FormMapper;
  
  class MyController extends CRUDController
  {
      public function getFieldAction()
    {
      //getting the value of choice field
      $type = $this-&gt;get('request')-&gt;get('type'); 
  
      //sonata.admin.reference is a service name of ReferenceBundle admin class
          $fieldDescription = $this-&gt;admin-&gt;getModelManager()
           -&gt;getNewFieldDescriptionInstance($this-&gt;admin-&gt;getClass(), 'reference');
          $fieldDescription-&gt;setAssociationAdmin($this-&gt;container-&gt;get('sonata.admin.reference'));
          $fieldDescription-&gt;setAdmin($this-&gt;admin);
          $fieldDescription-&gt;setAssociationMapping(array(
              'fieldName' =&gt; 'reference',
              'type' =&gt; ClassMetadataInfo::ONE_TO_MANY,
          ));
      
      // Getting form mapper in controller:
      $contractor = $this-&gt;container-&gt;get('sonata.admin.builder.orm_form');
      $mapper = new FormMapper($contractor, $this-&gt;admin-&gt;getFormBuilder(), $this-&gt;admin);
  
      $form_mapper = $mapper-&gt;add('reference', 'sonata_type_model_list', array(
              'translation_domain' =&gt; 'ReferenceBundle',
              'sonata_field_description' =&gt; $fieldDescription,
              'class' =&gt; $this-&gt;container-&gt;get('sonata.admin.reference')-&gt;getClass(),
              'model_manager' =&gt; $this-&gt;container-&gt;get('sonata.admin.reference')-&gt;getModelManager(),
              'label' =&gt; 'Reference',
              'required' =&gt; false,
          ));
  
  
      //@ToDo build $form from $form_mapper
  
  
      return $this-&gt;render('MyBundle:Form:field.view.html.twig', array(
          'form' =&gt; $form-&gt;createView(),
      ));
    }
  }
  </code></pre>
  <p>I cannot find any method in <code>Sonata\AdminBundle\Form\FormMapper</code> class to build a form (it seems to be possible with <code>create()</code> method, but it only works with common Symfony field types, not Sonata form field types, which are commonly generated in Block or Admin classes).</p>
  <p>Is it possible to use <code>Sonata\AdminBundle\Form\FormMapper</code> in the Controller to build a form?
  Or is there another way I can build a form with Sonata form field types in the Controller?</p>