Skip to content

Commit 3c81b52

Browse files
committed
feature #10272 [TwigBridge] Added form_twitter_bootstrap_x.y.z_layout.html.twig (lyrixx)
This PR was merged into the 2.6-dev branch. Discussion ---------- [TwigBridge] Added form_twitter_bootstrap_x.y.z_layout.html.twig | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | not yet Doc: ``` yaml # config.yml twig: form: resources: - form_twitter_bootstrap_2.3.x_layout.html.twig ``` or ```jinja {% form_theme form 'form_twitter_bootstrap_2.3.x_layout.html.twig' %} {{ form(form) }} ``` Commits ------- cfc04a6 [TwigBridge] Added form_twitter_bootstrap_layout.html.twig
2 parents ffd81ad + cfc04a6 commit 3c81b52

File tree

2 files changed

+303
-0
lines changed

2 files changed

+303
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{% extends "bootstrap_3_layout.html.twig" %}
2+
3+
{% block form_start -%}
4+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-horizontal')|trim}) %}
5+
{{- parent() -}}
6+
{%- endblock form_start %}
7+
8+
{# Labels #}
9+
10+
{% block form_label -%}
11+
{% spaceless %}
12+
{% if label is sameas(false) %}
13+
<div class="{{ block('form_label_class') }}"></div>
14+
{% else %}
15+
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ block('form_label_class'))|trim}) %}
16+
{{- parent() -}}
17+
{% endif %}
18+
{% endspaceless %}
19+
{%- endblock form_label %}
20+
21+
{% block form_label_class -%}
22+
col-sm-2
23+
{%- endblock form_label_class %}
24+
25+
{# Rows #}
26+
27+
{% block form_row -%}
28+
{% spaceless %}
29+
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
30+
{{ form_label(form) }}
31+
<div class="{{ block('form_group_class') }}">
32+
{{ form_widget(form) }}
33+
{{ form_errors(form) }}
34+
</div>
35+
</div>
36+
{% endspaceless %}
37+
{%- endblock form_row %}
38+
39+
{% block checkbox_row -%}
40+
{{- block('checkbox_radio_row') -}}
41+
{%- endblock checkbox_row %}
42+
43+
{% block radio_row -%}
44+
{{- block('checkbox_radio_row') -}}
45+
{%- endblock radio_row %}
46+
47+
{% block checkbox_radio_row -%}
48+
{% spaceless %}
49+
<div class="form-group{% if not valid %} has-error{% endif %}">
50+
<div class="{{ block('form_label_class') }}"></div>
51+
<div class="{{ block('form_group_class') }}">
52+
{{ form_widget(form) }}
53+
{{ form_errors(form) }}
54+
</div>
55+
</div>
56+
{% endspaceless %}
57+
{%- endblock checkbox_radio_row %}
58+
59+
{% block submit_row -%}
60+
{% spaceless %}
61+
<div class="form-group">
62+
<div class="{{ block('form_label_class') }}"></div>
63+
<div class="{{ block('form_group_class') }}">
64+
{{ form_widget(form) }}
65+
</div>
66+
</div>
67+
{% endspaceless %}
68+
{% endblock submit_row %}
69+
70+
{% block form_group_class -%}
71+
col-sm-10
72+
{%- endblock form_group_class %}
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
{% extends "form_div_layout.html.twig" %}
2+
3+
{# Widgets #}
4+
5+
{% block form_widget_simple -%}
6+
{% if type is not defined or 'file' != type %}
7+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) %}
8+
{% endif %}
9+
{{- parent() -}}
10+
{%- endblock form_widget_simple %}
11+
12+
{% block textarea_widget -%}
13+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) %}
14+
{{- parent() -}}
15+
{%- endblock textarea_widget %}
16+
17+
{% block submit_widget -%}
18+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' btn')|trim}) %}
19+
{{- parent() -}}
20+
{%- endblock %}
21+
22+
{% block button_widget -%}
23+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' btn')|trim}) %}
24+
{{- parent() -}}
25+
{%- endblock %}
26+
27+
{% block money_widget -%}
28+
<div class="input-group">
29+
{% set prepend = '{{' == money_pattern[0:2] %}
30+
{% if not prepend %}
31+
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
32+
{% endif %}
33+
{{- block('form_widget_simple') -}}
34+
{% if prepend %}
35+
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
36+
{% endif %}
37+
</div>
38+
{%- endblock money_widget %}
39+
40+
{% block percent_widget -%}
41+
<div class="input-group">
42+
{{- block('form_widget_simple') -}}
43+
<span class="input-group-addon">%</span>
44+
</div>
45+
{%- endblock percent_widget %}
46+
47+
{% block datetime_widget -%}
48+
{% if widget == 'single_text' %}
49+
{{- block('form_widget_simple') -}}
50+
{% else %}
51+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) %}
52+
<div {{ block('widget_container_attributes') }}>
53+
{{ form_errors(form.date) }}
54+
{{ form_errors(form.time) }}
55+
{{ form_widget(form.date, { datetime: true } ) }}&nbsp;
56+
{{ form_widget(form.time, { datetime: true } ) }}
57+
</div>
58+
{% endif %}
59+
{%- endblock datetime_widget %}
60+
61+
{% block date_widget -%}
62+
{% if widget == 'single_text' %}
63+
{{- block('form_widget_simple') -}}
64+
{% else %}
65+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) %}
66+
{% if datetime is not defined or not datetime %}
67+
<div {{ block('widget_container_attributes') -}}>
68+
{% endif %}
69+
{{ date_pattern|replace({
70+
'{{ year }}': form_widget(form.year),
71+
'{{ month }}': form_widget(form.month),
72+
'{{ day }}': form_widget(form.day),
73+
})|raw }}
74+
{% if datetime is not defined or not datetime %}
75+
</div>
76+
{% endif %}
77+
{% endif %}
78+
{%- endblock date_widget %}
79+
80+
{% block time_widget -%}
81+
{% if widget == 'single_text' %}
82+
{{- block('form_widget_simple') -}}
83+
{% else %}
84+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) %}
85+
{% if datetime is not defined or false == datetime %}
86+
<div {{ block('widget_container_attributes') -}}>
87+
{% endif %}
88+
{{ form_widget(form.hour) }}:{{ form_widget(form.minute) }}{% if with_seconds %}:{{ form_widget(form.second) }}{% endif %}
89+
{% if datetime is not defined or false == datetime %}
90+
</div>
91+
{% endif %}
92+
{% endif %}
93+
{%- endblock time_widget %}
94+
95+
{% block choice_widget_collapsed -%}
96+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) %}
97+
{{- parent() -}}
98+
{%- endblock %}
99+
100+
{% block choice_widget_expanded -%}
101+
{% if '-inline' in label_attr.class|default('') %}
102+
<div class="control-group">
103+
{% for child in form %}
104+
{{ form_widget(child, {
105+
parent_label_class: label_attr.class|default(''),
106+
}) }}
107+
{% endfor %}
108+
</div>
109+
{% else %}
110+
<div {{ block('widget_container_attributes') }}>
111+
{% for child in form %}
112+
{{ form_widget(child, {
113+
parent_label_class: label_attr.class|default(''),
114+
}) }}
115+
{% endfor %}
116+
</div>
117+
{% endif %}
118+
{%- endblock choice_widget_expanded %}
119+
120+
{% block checkbox_widget -%}
121+
{% set parent_label_class = parent_label_class|default('') %}
122+
{% if 'checkbox-inline' in parent_label_class %}
123+
{{ form_label(form, null, { widget: parent() }) }}
124+
{% else %}
125+
<div class="checkbox">
126+
{{ form_label(form, null, { widget: parent() }) }}
127+
</div>
128+
{% endif %}
129+
{%- endblock checkbox_widget %}
130+
131+
{% block radio_widget -%}
132+
{% set parent_label_class = parent_label_class|default('') %}
133+
{% if 'radio-inline' in parent_label_class %}
134+
{{ form_label(form, null, { widget: parent() }) }}
135+
{% else %}
136+
<div class="radio">
137+
{{ form_label(form, null, { widget: parent() }) }}
138+
</div>
139+
{% endif %}
140+
{%- endblock radio_widget %}
141+
142+
{# Labels #}
143+
144+
{% block form_label -%}
145+
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' control-label')|trim}) %}
146+
{{- parent() -}}
147+
{%- endblock form_label %}
148+
149+
{% block choice_label %}
150+
{# remove the checkbox-inline, it's only use full for embed labels #}
151+
{% set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': ''})|trim}) %}
152+
{{- block('form_label') -}}
153+
{% endblock %}
154+
155+
{% block checkbox_label -%}
156+
{{- block('checkbox_radio_label') -}}
157+
{%- endblock checkbox_label %}
158+
159+
{% block radio_label -%}
160+
{{- block('checkbox_radio_label') -}}
161+
{%- endblock radio_label %}
162+
163+
{% block checkbox_radio_label %}
164+
{% if required %}
165+
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %}
166+
{% endif %}
167+
{% if parent_label_class is defined %}
168+
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ parent_label_class)|trim}) %}
169+
{% endif %}
170+
{% if label is empty %}
171+
{% set label = name|humanize %}
172+
{% endif %}
173+
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
174+
{{ widget|raw }}
175+
{{ label|trans({}, translation_domain) }}
176+
</label>
177+
{% endblock checkbox_radio_label %}
178+
179+
{# Rows #}
180+
181+
{% block form_row -%}
182+
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
183+
{{ form_label(form) }}
184+
{{ form_widget(form) }}
185+
{{ form_errors(form) }}
186+
</div>
187+
{%- endblock form_row %}
188+
189+
{% block choice_row -%}
190+
{% set force_error = true %}
191+
{{ block('form_row') }}
192+
{%- endblock choice_row %}
193+
194+
{% block date_row -%}
195+
{% set force_error = true %}
196+
{{ block('form_row') }}
197+
{%- endblock date_row %}
198+
199+
{% block time_row -%}
200+
{% set force_error = true %}
201+
{{ block('form_row') }}
202+
{%- endblock time_row %}
203+
204+
{% block datetime_row -%}
205+
{% set force_error = true %}
206+
{{ block('form_row') }}
207+
{%- endblock datetime_row %}
208+
209+
{% block checkbox_row -%}
210+
<div class="form-group{% if not valid %} has-error{% endif %}">
211+
{{ form_widget(form) }}
212+
{{ form_errors(form) }}
213+
</div>
214+
{%- endblock checkbox_row %}
215+
216+
{% block radio_row -%}
217+
<div class="form-group{% if not valid %} has-error{% endif %}">
218+
{{ form_widget(form) }}
219+
{{ form_errors(form) }}
220+
</div>
221+
{%- endblock radio_row %}
222+
223+
{# Errors #}
224+
225+
{% block form_errors -%}
226+
{% if errors|length > 0 %}
227+
{% if form.parent %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
228+
{{- parent() -}}
229+
{% if form.parent %}</span>{% else %}</div>{% endif %}
230+
{% endif %}
231+
{%- endblock form_errors %}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy