nielsv
nielsv

Reputation: 6800

SonataAdmin - Custom form template for each form

I'm having problems with Sonata Admin Bundle. What I would like to do is:

Add some text before some labels in my form. Like for example:

The resolution of your image must be ..x.. .

For example I have a form like this:

protected function configureFormFields(FormMapper $formMapper)
{
     $formMapper
         ->add('locale', 'choice', array(
             'choices'   => array('nl' => 'NL', 'en' => 'EN'),
             'required'  => true,
         ))
         ->add('pageid.tag', 'text', array('label' => 'Tag'))
         ->add('description', 'text', array('label' => 'Beschrijving'))
         ->add('content', 'textarea', array('label' => 'Tekst', 'attr' => array('class' => 'ckeditor')))
         ->add('files', 'file', array('required' => false, 'multiple' => true))
    ;
}

Now I would like to add some text before my files input field.

What I've done now is:

But this will be used for every form, can't I set specific form templates for specific forms?

Upvotes: 1

Views: 1281

Answers (2)

Piotr Galas
Piotr Galas

Reputation: 4776

You can specify form template in your admin class overriding getFormTheme method. Add this code to your admin class.

public function getFormTheme()
{
     return array_merge(
         parent::getFormTheme(),
         array('MurisBundle:PageAdmin:form_admin_fields.html.twig')
     );
} 

Upvotes: 1

Cristian Bujoreanu
Cristian Bujoreanu

Reputation: 1167

getPictureUrlFull().'" alt="'.$campaign->getPicture().'" style="margin-top:10px;" />Use "help"

protected function configureFormFields(FormMapper $formMapper)
{
     $formMapper
         ->add('locale', 'choice', array(
             'choices'   => array('nl' => 'NL', 'en' => 'EN'),
             'required'  => true,
             'help'      => '<img src="'.$entity->getPictureUrlFull().'" alt="'.$entity->getPicture().'" />'               
         ))

)

Upvotes: 0

Related Questions