奏鸣曲管理员添加类以编辑表单

时间:2018-11-14 09:56:20

标签: symfony sonata-admin

我尝试将类添加到表单

 protected function configureFormFields(FormMapper $formMapper)



 $formMapper->getFormBuilder()->getAttributes()['test']='sdsd';
    $formMapper->getFormBuilder()->setAttribute('class','data-mea-postboxSonataEdit');
    $formMapper->getFormBuilder()->setAttribute('attr',['class'=>'sasd']);

,但未显示。可以添加吗?

2 个答案:

答案 0 :(得分:1)

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->add('linkType', ChoiceFieldMaskType::class, [
            'choices' => [
                'uri' => 'uri',
                'route' => 'route',
            ],
            'map' => [
                'route' => ['route', 'parameters'],
                'uri' => ['uri'],
            ],
            'placeholder' => 'Choose an option',
            'required' => false,
            'class' => sasd,
        ])
    ;
 }

来自here

答案 1 :(得分:1)

使用configureFormFields可以更改表单中的字段或组字段,但是如果要向整个表单中添加类,建议您使用模板在配置中定义

sonata_admin:
    templates:
        # default global templates
        layout:  "@SonataAdmin/standard_layout.html.twig"
        ajax:    "@SonataAdmin/ajax_layout.html.twig"

        # default value if done set, actions templates, should extend global templates
        list:    "@SonataAdmin/CRUD/list.html.twig"
        show:    "@SonataAdmin/CRUD/show.html.twig"
        edit:    "@SonataAdmin/CRUD/edit.html.twig"