Sonata 管理员添加 class 以编辑表单

Sonata admin add class to edit form

我尝试添加 class 形成

 protected function configureFormFields(FormMapper $formMapper)



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

但未显示。可以添加吗?

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

使用configureFormFields你可以在一个表单中更改字段或分组字段,但是如果你想在整个表单中添加一个class,我建议你使用模板,在配置

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"