title: Symfony2 - use Sonata field type outside the bundle
body: <p>I would like to have good looking <code>EntityType</code> for <code>multiple</code> selection as Sonata does with <code>sonata_type_model</code> (<code>ModelType</code>).</p>
  
  <p>The question would be, how can I use <code>sonata_type_model</code> outside <code>SonataAdminBundle</code> on my custom form?</p>
  
  <p>I tried:</p>
  
  <pre><code>-&gt;add('countries', 'sonata_type_model', array(
      'label' =&gt; 'Countries',
      'property' =&gt; 'name',
      'multiple' =&gt; true
  ))
  </code></pre>
  
  <p>Also I tried:</p>
  
  <pre><code>use Sonata\AdminBundle\Form\Type\ModelType;
  
  ...
  
  -&gt;add('countries', ModelType::class, array(
      'label' =&gt; 'Countries',
      'property' =&gt; 'name',
      'multiple' =&gt; true
  ))
  </code></pre>
  
  <p>But unfortunately I am getting an error:</p>
  
  <blockquote>
    <p>Catchable Fatal Error: Argument 1 passed to
    Sonata\AdminBundle\Form\ChoiceList\ModelChoiceLoader::__construct()
    must implement interface
    Sonata\AdminBundle\Model\ModelManagerInterface, null given, called in
    C:\xampp\htdocs\trainingexperience_symfony\app\cache\dev\classes.php
    on line 18005 and defined</p>
  </blockquote>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I followed an advice to define <code>model_manager</code> property inside form type options:</p>
  
  <pre><code>protected $modelManager;
  
  function __construct(ModelManager $modelManager)
  {
      $this-&gt;modelManager = $modelManager;
  }
  
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('preferredCountries', ModelType::class, array(
              'label' =&gt; 'Countries',
              'property' =&gt; 'name',
              'multiple' =&gt; true,
              'model_manager' =&gt; $this-&gt;modelManager
          ));
  
      ...
  }
  </code></pre>
  
  <p>I pass it from controller like:</p>
  
  <pre><code>/** @var ModelManager $modelManager */
  $modelManager = $this-&gt;get('sonata.media.admin.media.manager');
  $formType = new FormType($modelManager);
  
  ...
  </code></pre>
  
  <p>But now I get an error:</p>
  
  <blockquote>
    <p>Class does not exist </p>
    
    <p>500 Internal Server Error - ReflectionException</p>
  </blockquote>
  
  <p><strong>Stack Trace</strong></p>
  
  <pre><code>in vendor\doctrine\common\lib\Doctrine\Common\Persistence\AbstractManagerRegistry.php at line 197   -
  
     $class = $this-&gt;getAliasNamespace($namespaceAlias) . '\\' . $simpleClassName; 
          } 
          $proxyClass = new \ReflectionClass($class); 
          if ($proxyClass-&gt;implementsInterface($this-&gt;proxyInterfaceName)) { 
              if (! $parentClass = $proxyClass-&gt;getParentClass()) { 
  
  at ReflectionClass -&gt;__construct ('') 
  in vendor\doctrine\common\lib\Doctrine\Common\Persistence\AbstractManagerRegistry.php at line 197   + 
  at AbstractManagerRegistry -&gt;getManagerForClass (null) 
  in vendor\sonata-project\doctrine-orm-admin-bundle\Model\ModelManager.php at line 272   + 
  at ModelManager -&gt;getEntityManager (null) 
  in vendor\sonata-project\doctrine-orm-admin-bundle\Model\ModelManager.php at line 64   + 
  at ModelManager -&gt;getMetadata (null) 
  in vendor\sonata-project\doctrine-orm-admin-bundle\Model\ModelManager.php at line 377   + 
  at ModelManager -&gt;getIdentifierFieldNames (null) 
  in vendor\sonata-project\admin-bundle\Form\ChoiceList\ModelChoiceLoader.php at line 75   + 
  at ModelChoiceLoader -&gt;__construct (object(ModelManager), null, 'name', null, array(), object(PropertyAccessor)) 
  in vendor\sonata-project\admin-bundle\Form\Type\ModelType.php at line 113   + 
  at ModelType -&gt;Sonata\AdminBundle\Form\Type\{closure} (object(OptionsResolver), null) 
  in vendor\symfony\symfony\src\Symfony\Component\OptionsResolver\OptionsResolver.php at line 859   + 
  at OptionsResolver -&gt;offsetGet ('choice_loader') 
  in vendor\symfony\symfony\src\Symfony\Component\Form\Extension\Core\Type\ChoiceType.php at line 320   + 
  at ChoiceType -&gt;Symfony\Component\Form\Extension\Core\Type\{closure} (object(OptionsResolver), null) 
  in vendor\symfony\symfony\src\Symfony\Component\OptionsResolver\OptionsResolver.php at line 965   + 
  at OptionsResolver -&gt;offsetGet ('choice_list') 
  in vendor\symfony\symfony\src\Symfony\Component\OptionsResolver\OptionsResolver.php at line 791   + 
  at OptionsResolver -&gt;resolve (array('label' =&gt; 'Countries', 'property' =&gt; 'name', 'multiple' =&gt; true, 'model_manager' =&gt; object(ModelManager))) 
  in vendor\symfony\symfony\src\Symfony\Component\Form\ResolvedFormType.php at line 156   + 
  at ResolvedFormType -&gt;createBuilder (object(FormFactory), 'preferredCountries', array('label' =&gt; 'Countries', 'property' =&gt; 'name', 'multiple' =&gt; true, 'model_manager' =&gt; object(ModelManager))) 
  in vendor\symfony\symfony\src\Symfony\Component\Form\Extension\DataCollector\Proxy\ResolvedTypeDataCollectorProxy.php at line 89  + 
  at ResolvedTypeDataCollectorProxy -&gt;createBuilder (object(FormFactory), 'preferredCountries', array('label' =&gt; 'Countries', 'property' =&gt; 'name', 'multiple' =&gt; true, 'model_manager' =&gt; object(ModelManager))) 
  in vendor\symfony\symfony\src\Symfony\Component\Form\FormFactory.php at line 114   + 
  at FormFactory -&gt;createNamedBuilder ('preferredCountries', 'Sonata\AdminBundle\Form\Type\ModelType', null, array('label' =&gt; 'Countries', 'property' =&gt; 'name', 'multiple' =&gt; true, 'model_manager' =&gt; object(ModelManager))) 
  in vendor\symfony\symfony\src\Symfony\Component\Form\FormBuilder.php at line 106   + 
  at FormBuilder -&gt;create ('preferredCountries', 'Sonata\AdminBundle\Form\Type\ModelType', array('label' =&gt; 'Countries', 'property' =&gt; 'name', 'multiple' =&gt; true, 'model_manager' =&gt; object(ModelManager))) 
  in vendor\symfony\symfony\src\Symfony\Component\Form\FormBuilder.php at line 269   + 
  at FormBuilder -&gt;resolveChildren () 
  in vendor\symfony\symfony\src\Symfony\Component\Form\FormBuilder.php at line 215   + 
  at FormBuilder -&gt;getForm () 
  in vendor\symfony\symfony\src\Symfony\Component\Form\FormFactory.php at line 40   + 
  at FormFactory -&gt;create (object(InternshipType), object(Internship), array()) 
  in vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php at line 282   + 
  at Controller -&gt;createForm (object(InternshipType), object(Internship)) 
  in src\IndexBundle\Controller\TraineeController.php at line 194   + 
  at TraineeController -&gt;internshipsAction (object(Request)) 
  at call_user_func_array (array(object(TraineeController), 'internshipsAction'), array(object(Request))) 
  in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 144   + 
  at HttpKernel -&gt;handleRaw (object(Request), '1') 
  in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 64   + 
  at HttpKernel -&gt;handle (object(Request), '1', true) 
  in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel.php at line 69   + 
  at ContainerAwareHttpKernel -&gt;handle (object(Request), '1', true) 
  in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php at line 185   + 
  at Kernel -&gt;handle (object(Request)) 
  in web\app_dev.php at line 30   + 
  </code></pre>