By default in the base theme form:
{% block form_row %} {% spaceless %} <div> {{ form_label(form) }} {{ form_errors(form) }} {{ form_widget(form) }} </div> {% endspaceless %} {% endblock form_row %}
And for custom compound forms:
{% block form_widget_compound %} {% spaceless %} <div {{ block('widget_container_attributes') }}> {% if form.parent is empty %} {{ form_errors(form) }} {% endif %} {{ block('form_rows') }} {{ form_rest(form) }} </div> {% endspaceless %} {% endblock form_widget_compound %}
If you have not changed anything here, the DIV that you see should come from one or the other bit of the template.
However, in your specific example, if form_tutor_user_row is defined, the first bit is never used, and if form_tutor_user_widget is defined, the last bit is never used.
Let's get back to your question. Your question: "How can I change the theme so that all user types are not wrapped by the default form_row form template?"
This is the problem, as I see it: you want your TOP-forms (the form in which all sub-forms were included) to have a common way of rendering in sections. Each section will be included in the DIV with class = "form-group". You might want to add some additional rendering operations, but I will limit myself to keeping things simple.
What you need to do is create the type of the specified form and make all of your TOP forms inherited from this new form type. For example:
class TopType extends AbstractType { public function getName() { return 'top_form'; } }
... and the inherited form:
class MyFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { ... } public function getName() { return 'my_form'; } public function getParent() { return 'top_form'; } }
As you can see, there is no need to inherit PHP inheritance for type inheritance inheritance.
The-theming-wise template (can I even say this?), If my_form is not given a specific form task, Symfony will understand that the default form theme to use here is the top_form form theme , which you can define as such:
{% block top_form_widget %} {% spaceless %} {% for child in form %} <div class="form-group"> {{ form_widget(child) }} </div> {% endfor %} {{ form_rest(form) }} {% endspaceless %} {% endblock top_form_widget %}
I must add that this is a problem that I have already encountered and solved. Tell us how it works for you.
Edit:
To summarize, you need to do the following:
- Create a TopType form type,
- Add a top_form_widget block in the form theme,
- For all your root forms (i.e. top-level forms, forms that don't have a parent) add a getParent () method that will return your TopType form name ("top_form")