I would like to customize the rendering of a form field in the edit page from sonata admin bundle to include an applet that uses the text content of a field.
I know that I have to edit the configureFormFields
function in the admin class, but I need to know 3 things:
- What is the syntax to provide a field form template
- Where to put the template file ( which directory )
- What the template have to looks like.
user1254498's solution won't work unless the block name prefix matches the name of the form type. At least with the last version of sonata admin bundle (2.2.12). In this case:
And, regarding
getFormTheme()
, you shoud return also the parent theme, otherwise you may break the whole style...Also, you can access the admin service in the twig template with the variable
sonata_admin.admim
.Found a solution
What i have done is:
Created a field type, lets call it myfieldType in myCompany\myBundle\Form\Type\myfieldType.php
Registered the Type in app/config/services.yml
In my myentityAdmin class,
and
and the template :
And now i can access the form field value by the twig variable "value" !
So easy... when you got it.
In your services.yml file you define the template for your edit Action:
In that template you can then override templates for fields in your form:
Then my template looks like that:
In this case, my countries check boxes appear in column of 60 elements, not in one column with the whole list of elements.
Hope this is helpful to someone else.