简体   繁体   中英

Sonata admin add class to edit form

I try add class to form

 protected function configureFormFields(FormMapper $formMapper)



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

but it not shown. Is possible to add it ?

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,
        ])
    ;
 }

from here

With configureFormFields you can change fields or group fields inside a form, but if you want to add a class to the whole form, I suggest you to use a template, to define in configuration

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"

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