{% extends 'form_div_layout.html.twig' %} {# Voir https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig #} {# On commence par simplement ajouter le form-group au row de nos formulaires #} {% block form_row -%} {% set attr = attr|merge({'help': (attr.help|default(true)) }) %}
{{- form_label(form) }} {{- form_widget(form) }} {{ form_errors(form) }}
{%- endblock form_row %} {# Puis on modifie très simplement nos input et textarea les plus importants pour y ajouter le class imposée par Bootstrap 3 #} {% block textarea_widget %} {% set attr = attr|merge({'class': attr.class|default('') ~ ' form-control'}) %} {{ parent() }} {% endblock textarea_widget %} {% block form_widget_simple %} {% set attr = attr|merge({'class': attr.class|default('') ~ ' form-control'}) %} {{ parent() }} {% endblock form_widget_simple %} {% block form_label -%} {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' control-label')|trim}) %} {% if 'checkbox' not in block_prefixes %} {% if label is not same as(false) -%} {% if not compound -%} {% set label_attr = label_attr|merge({'for': id}) %} {%- endif %} {% if required -%} {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %} {%- endif %} {% if label is empty -%} {% set label = name|humanize %} {%- endif -%} {{ label|trans({}, translation_domain)|raw }} {% if required %}*{% endif %} {%- endif %} {% endif %} {%- endblock form_label %} {# et enfin les erreurs #} {% block form_errors %} {% if errors|length > 0 %} {% if attr.help is defined and attr.help %}

{% for error in errors %} {{ error.message }}
{% endfor %}

{% else %}
{% for error in errors %} {{ error.message|raw }}
{% endfor %}
{% endif %} {% endif %} {% endblock form_errors %} {# Personnalisation des boutons #} {% block button_widget -%} {% if label is empty -%} {% set label = name|humanize %} {%- endif -%} {% set attr = attr|merge({'class': (attr.class|default('') ~ '')|trim}) %} {%- endblock button_widget %} {# Personnalisation des attributs des boutons #} {% block button_attributes -%} {% if type is defined and type == 'submit' -%} {% set class = 'btn-primary' %} {% else %} {% set class = 'btn-default' %} {%- endif -%} {% set attr = attr|merge({'class': (attr.class|default('') ~ ' btn ' ~ class)|trim}) %} {{ parent() }} {%- endblock button_attributes %} {# Personnalisation des select #} {% block choice_widget_collapsed %} {% set attr = attr|merge({'class': (attr.class|default('') ~ ' form-control')|trim}) %} {{ parent() }} {%- endblock choice_widget_collapsed %} {% block choice_widget %} {% if expanded %} {% else %} {{ parent() }} {% endif %} {% endblock choice_widget %} {% block checkbox_widget %} {% endblock checkbox_widget %} {% block radio_widget %}    {% endblock radio_widget %} {# Inline date marcro #} {% macro date_form_widget(form) %}
{{ form_widget(form) }}
{% endmacro %} {# Inline date #} {% block date_widget %} {% if widget == 'single_text' %} {{ block('form_widget_simple') }} {% else %} {% import _self as self %}
{{ date_pattern|replace({ '{{ year }}': self.date_form_widget(form.year), '{{ month }}': self.date_form_widget(form.month), '{{ day }}': self.date_form_widget(form.day), })|raw }}
{% endif %} {% endblock date_widget %} {# Inline date_time {% block time_widget %} {% if widget == 'single_text' %} {{ block('form_widget_simple') }} {% else %} {% import _self as self %}
{{ time_pattern|replace({ '{{ hour }}': self.date_form_widget(form.hour), '{{ minute }}': self.date_form_widget(form.minute), })|raw }}
{% endif %} {% endblock time_widget %} #} {% block file_widget %} {% set type = type|default('file') %} {% endblock file_widget %}