setting default value in symfony2 sonata admin bundle

后端 未结 4 2010
清歌不尽
清歌不尽 2020-12-28 17:08

how can i set default value in sonata admin bundle the data option is missing in configureFormFields method

protected function configureFormFields(FormMappe         


        
4条回答
  •  轮回少年
    2020-12-28 17:26

    For booleans, another option is to set a data value within the first array passed to your add method, inside of configureFormFields

    So after some memtoring, my code (for a checkbox that I wanted to have checked by default) ended up looking something like this:

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('name')
            ->add('visible', null, ['label'=>'Visibility', 'data' => true ])
        ;
    }
    

    ... which saved a few lines at the top of my file, since I could then get rid of the getNewInstance() definition.

提交回复
热议问题