简体   繁体   English

Sonata admin datagrid 过滤器无法让 ChoiceType 工作

[英]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.在 Sonata admin 3.x 上,我在列表视图中有这个过滤器,提供了一个 select 框,其中包含所描述的选项。


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:但是在升级到 4.x 时出现以下错误:

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.我尝试了 ChoiceType 到 ChoiceFilter 之间的所有内容,但我在文档上找不到任何片段或任何有关现在应该如何工作的相关提示。

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

                    ]
                ]
            )
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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