简体   繁体   中英

Sonata admin datagrid filter can't get ChoiceType to work

I'm removing my hairs over this one. On sonata admin 3.x I had this filter in the list view, providing a select box with the options described.


protected function configureDatagridFilters(DatagridMapper $datagridMapper): void 
{
    ->add('state', 'doctrine_orm_choice',
                array('label' => 'State'),
                ChoiceType::class, array(
                    'choices' => array(
                        'new' => 'new',
                        'open' => 'open',
                        'closed' => 'closed' ),
                        'required' => false

                    )
            )
}

But on the upgrade to 4.x I got the following error:

No attached service to type named 'doctrine_orm_choice'

I tried everything between the ChoiceType, to the ChoiceFilter but I can't find any snippet on the docs or any relevant cue on how this is supposed to work now.

Thanks a lot !

And the correct syntax is:

use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter;

protected function configureDatagridFilters(DatagridMapper $datagridMapper): void 
{
     ->add('state',   ChoiceFilter::class, ['label' => 'State',
                    'field_type' => ChoiceType::class,
                    'field_options' => [
                        'choices' => [
                            'new' => 'new',
                            'open' => 'open',
                            'closed' => 'closed'],
                        'required' => 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