Developer
Developer

Reputation: 2895

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 ?

Upvotes: 1

Views: 1767

Answers (2)

hoover_D
hoover_D

Reputation: 650

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"

Upvotes: 1

mohamed jebri
mohamed jebri

Reputation: 271

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

Upvotes: 1

Related Questions