简体   繁体   中英

Sonata mongodb admin bundle filter by reference

I have document with

/** @MongoDB\\ReferenceMany(targetDocument="NewsTag") */ private $tags;

relation.

In my sonata admin i want to filter list by tag. I try to use

$datagridMapper->add('tags', null, array(), null, array('expanded' => true, 'multiple' => true))

as in documentation, but have an error

Could not load type "document"

Anybody know why?

UPD: stack trace

Symfony\Component\Form\Exception\InvalidArgumentException: Could not load type "document"
at n/a
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php line 87

at Symfony\Component\Form\FormRegistry->getType('document')
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 83

at Symfony\Component\Form\FormFactory->createNamedBuilder('value', 'document', null, array('required' => false, 'class' => 'AppBundle\Document\NewsTag', 'expanded' => true, 'multiple' => true))
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 106

at Symfony\Component\Form\FormBuilder->create('value', 'document', array('required' => false, 'class' => 'AppBundle\Document\NewsTag', 'expanded' => true, 'multiple' => true))
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 267

at Symfony\Component\Form\FormBuilder->resolveChildren()
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 215

at Symfony\Component\Form\FormBuilder->getForm()
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 221

at Symfony\Component\Form\FormBuilder->getForm()
    in /var/www/meteoprog-site-s3/var/cache/dev/classes.php line 11085

at Sonata\AdminBundle\Datagrid\Datagrid->buildPager()
    in /var/www/meteoprog-site-s3/var/cache/dev/classes.php line 11189

at Sonata\AdminBundle\Datagrid\Datagrid->getForm()
    in /var/www/meteoprog-site-s3/vendor/sonata-project/admin-bundle/Controller/CRUDController.php line 105

at Sonata\AdminBundle\Controller\CRUDController->listAction()
    in  line 

at call_user_func_array(array(object(LanguagesAdminController), 'listAction'), array())
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 139

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 62

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
    in /var/www/meteoprog-site-s3/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 169

at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
    in /var/www/meteoprog-site-s3/web/app_dev.php line 30

So if you want to filter with sonata_type_model probably a bug hapens. You don't have modelManager in ChoiceField. But you can manually add it in configureDatagridFilters like this:

   $datagridMapper
        ->add('tags', null, [], 'sonata_type_model',
            [
                'model_manager' => $datagridMapper->getAdmin()->getModelManager(), 
                'property' => 'name', 
                'multiple' => true, 
                'by_reference' => false
            ]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM