AntonioCS
AntonioCS

Reputation: 8496

Sonata custom field in admin class

I created a new field type and I am trying to use it in sonata. In one of my admin classes I have the following:

$formMapper
                    ->add('name', 'text')
                    ->add('img_home', new \MyBundle\Form\Type\ImageType(), array(
                        'required' => false,
                        'mapped' => false,
                        'label' => 'home set image',
                        'attr' => array('src' => '/' . $home)
                            )
                    )

When I do this on the img_home field I trigger this exception

'Please define a type for field ...'

https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/master/Builder/FormContractor.php#L56

If I comment out this exception everything works fine. I see the field I want without any issues.

How can I fix this without having to change the code?

Upvotes: 2

Views: 2146

Answers (1)

AntonioCS
AntonioCS

Reputation: 8496

Found the solution. After reading the code I noticed that there is a 4th argument you can pass and sonatas code checks if the array passed has they 'type' key. So I just added :

array('type' => 'string')

As the 4th parameter

Upvotes: 4

Related Questions