]> Raphaƫl G. Git Repositories - airbundle/blob - Resources/views/form/form_div_layout.html.twig
Fix coalesce warning
[airbundle] / Resources / views / form / form_div_layout.html.twig
1 {# Widgets #}
2
3 {%- block form_widget -%}
4 {% if compound %}
5 {{- block('form_widget_compound') -}}
6 {% else %}
7 {{- block('form_widget_simple') -}}
8 {% endif %}
9 {%- endblock form_widget -%}
10
11 {%- block form_widget_simple -%}
12 {%- set type = type|default('text') -%}
13 <input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
14 {%- endblock form_widget_simple -%}
15
16 {%- block form_widget_compound -%}
17 <div {{ block('widget_container_attributes') }}>
18 {%- if form is rootform -%}
19 {{ form_errors(form) }}
20 {%- endif -%}
21 {{- block('form_rows') -}}
22 {{- form_rest(form) -}}
23 </div>
24 {%- endblock form_widget_compound -%}
25
26 {%- block collection_widget -%}
27 {% if prototype is defined %}
28 {%- set attr = attr|merge({'data-prototype': form_row(prototype) }) -%}
29 {% endif %}
30 {{- block('form_widget') -}}
31 {%- endblock collection_widget -%}
32
33 {%- block textarea_widget -%}
34 <textarea {{ block('widget_attributes') }}>{{ value }}</textarea>
35 {%- endblock textarea_widget -%}
36
37 {%- block choice_widget -%}
38 {% if expanded %}
39 {{- block('choice_widget_expanded') -}}
40 {% else %}
41 {{- block('choice_widget_collapsed') -}}
42 {% endif %}
43 {%- endblock choice_widget -%}
44
45 {%- block choice_widget_expanded -%}
46 {%- for child in form %}
47 <div class="row" {{ block('widget_container_attributes') }}>
48 {{- form_label(child, null, {translation_domain: choice_translation_domain}) -}}
49 <div>
50 {{- form_widget(child) -}}
51 </div>
52 </div>
53 {% endfor -%}
54 {%- endblock choice_widget_expanded -%}
55
56 {%- block choice_widget_collapsed -%}
57 {%- if required and placeholder is none and not placeholder_in_choices and not multiple and (attr.size is not defined or attr.size <= 1) -%}
58 {% set required = false %}
59 {%- endif -%}
60 <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
61 {%- if placeholder is not none -%}
62 <option value=""{% if required and value is empty %} selected="selected"{% endif %}>{{ placeholder != '' ? (translation_domain is same as(false) ? placeholder : placeholder|trans({}, translation_domain)) }}</option>
63 {%- endif -%}
64 {%- if preferred_choices|length > 0 -%}
65 {% set options = preferred_choices %}
66 {{- block('choice_widget_options') -}}
67 {%- if choices|length > 0 and separator is not none -%}
68 <option disabled="disabled">{{ separator }}</option>
69 {%- endif -%}
70 {%- endif -%}
71 {%- set options = choices -%}
72 {{- block('choice_widget_options') -}}
73 </select>
74 {%- endblock choice_widget_collapsed -%}
75
76 {%- block choice_widget_options -%}
77 {% for group_label, choice in options %}
78 {%- if choice is iterable -%}
79 <optgroup label="{{ choice_translation_domain is same as(false) ? group_label : group_label|trans({}, choice_translation_domain) }}">
80 {% set options = choice %}
81 {{- block('choice_widget_options') -}}
82 </optgroup>
83 {%- else -%}
84 <option value="{{ choice.value }}"{% if choice.attr %}{% with { attr: choice.attr } %}{{ block('attributes') }}{% endwith %}{% endif %}{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice_translation_domain is same as(false) ? choice.label : choice.label|trans({}, choice_translation_domain) }}</option>
85 {%- endif -%}
86 {% endfor %}
87 {%- endblock choice_widget_options -%}
88
89 {%- block checkbox_widget -%}
90 <input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
91 {%- endblock checkbox_widget -%}
92
93 {%- block radio_widget -%}
94 <input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
95 {%- endblock radio_widget -%}
96
97 {%- block datetime_widget -%}
98 {% if widget == 'single_text' %}
99 {{- block('form_widget_simple') -}}
100 {%- else -%}
101 <div {{ block('widget_container_attributes') }}>
102 {{- form_errors(form.date) -}}
103 {{- form_errors(form.time) -}}
104 {{- form_widget(form.date) -}}
105 {{- form_widget(form.time) -}}
106 </div>
107 {%- endif -%}
108 {%- endblock datetime_widget -%}
109
110 {%- block date_widget -%}
111 {%- if widget == 'single_text' -%}
112 {{ block('form_widget_simple') }}
113 {%- else -%}
114 <div {{ block('widget_container_attributes') }}>
115 {{- date_pattern|replace({
116 '{{ year }}': form_widget(form.year),
117 '{{ month }}': form_widget(form.month),
118 '{{ day }}': form_widget(form.day),
119 })|raw -}}
120 </div>
121 {%- endif -%}
122 {%- endblock date_widget -%}
123
124 {%- block time_widget -%}
125 {%- if widget == 'single_text' -%}
126 {{ block('form_widget_simple') }}
127 {%- else -%}
128 {%- set vars = widget == 'text' ? { 'attr': { 'size': 1 }} : {} -%}
129 <div {{ block('widget_container_attributes') }}>
130 {{ form_widget(form.hour, vars) }}{% if with_minutes %}:{{ form_widget(form.minute, vars) }}{% endif %}{% if with_seconds %}:{{ form_widget(form.second, vars) }}{% endif %}
131 </div>
132 {%- endif -%}
133 {%- endblock time_widget -%}
134
135 {%- block dateinterval_widget -%}
136 {%- if widget == 'single_text' -%}
137 {{- block('form_widget_simple') -}}
138 {%- else -%}
139 <div {{ block('widget_container_attributes') }}>
140 {{- form_errors(form) -}}
141 <table class="{{ table_class|default('') }}" role="presentation">
142 <thead>
143 <tr>
144 {%- if with_years %}<th>{{ form_label(form.years) }}</th>{% endif -%}
145 {%- if with_months %}<th>{{ form_label(form.months) }}</th>{% endif -%}
146 {%- if with_weeks %}<th>{{ form_label(form.weeks) }}</th>{% endif -%}
147 {%- if with_days %}<th>{{ form_label(form.days) }}</th>{% endif -%}
148 {%- if with_hours %}<th>{{ form_label(form.hours) }}</th>{% endif -%}
149 {%- if with_minutes %}<th>{{ form_label(form.minutes) }}</th>{% endif -%}
150 {%- if with_seconds %}<th>{{ form_label(form.seconds) }}</th>{% endif -%}
151 </tr>
152 </thead>
153 <tbody>
154 <tr>
155 {%- if with_years %}<td>{{ form_widget(form.years) }}</td>{% endif -%}
156 {%- if with_months %}<td>{{ form_widget(form.months) }}</td>{% endif -%}
157 {%- if with_weeks %}<td>{{ form_widget(form.weeks) }}</td>{% endif -%}
158 {%- if with_days %}<td>{{ form_widget(form.days) }}</td>{% endif -%}
159 {%- if with_hours %}<td>{{ form_widget(form.hours) }}</td>{% endif -%}
160 {%- if with_minutes %}<td>{{ form_widget(form.minutes) }}</td>{% endif -%}
161 {%- if with_seconds %}<td>{{ form_widget(form.seconds) }}</td>{% endif -%}
162 </tr>
163 </tbody>
164 </table>
165 {%- if with_invert %}{{ form_widget(form.invert) }}{% endif -%}
166 </div>
167 {%- endif -%}
168 {%- endblock dateinterval_widget -%}
169
170 {%- block number_widget -%}
171 {# type="number" doesn't work with floats #}
172 {%- set type = type|default('text') -%}
173 {{ block('form_widget_simple') }}
174 {%- endblock number_widget -%}
175
176 {%- block integer_widget -%}
177 {%- set type = type|default('number') -%}
178 {{ block('form_widget_simple') }}
179 {%- endblock integer_widget -%}
180
181 {%- block money_widget -%}
182 {{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
183 {%- endblock money_widget -%}
184
185 {%- block url_widget -%}
186 {%- set type = type|default('url') -%}
187 {{ block('form_widget_simple') }}
188 {%- endblock url_widget -%}
189
190 {%- block search_widget -%}
191 {%- set type = type|default('search') -%}
192 {{ block('form_widget_simple') }}
193 {%- endblock search_widget -%}
194
195 {%- block percent_widget -%}
196 {%- set type = type|default('text') -%}
197 {{ block('form_widget_simple') }} %
198 {%- endblock percent_widget -%}
199
200 {%- block password_widget -%}
201 {%- set type = type|default('password') -%}
202 {{ block('form_widget_simple') }}
203 {%- endblock password_widget -%}
204
205 {%- block hidden_widget -%}
206 {%- set type = type|default('hidden') -%}
207 {{ block('form_widget_simple') }}
208 {%- endblock hidden_widget -%}
209
210 {%- block email_widget -%}
211 {%- set type = type|default('email') -%}
212 {{ block('form_widget_simple') }}
213 {%- endblock email_widget -%}
214
215 {%- block range_widget -%}
216 {% set type = type|default('range') %}
217 {{- block('form_widget_simple') -}}
218 {%- endblock range_widget %}
219
220 {%- block button_widget -%}
221 {%- if label is empty -%}
222 {%- if label_format is not empty -%}
223 {% set label = label_format|replace({
224 '%name%': name,
225 '%id%': id,
226 }) %}
227 {%- elseif label is same as(false) -%}
228 {% set translation_domain = false %}
229 {%- else -%}
230 {% set label = name|humanize %}
231 {%- endif -%}
232 {%- endif -%}
233 <button type="{{ type|default('button') }}" {{ block('button_attributes') }}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}</button>
234 {%- endblock button_widget -%}
235
236 {%- block submit_widget -%}
237 {%- set type = type|default('submit') -%}
238 {{ block('button_widget') }}
239 {%- endblock submit_widget -%}
240
241 {%- block reset_widget -%}
242 {%- set type = type|default('reset') -%}
243 {{ block('button_widget') }}
244 {%- endblock reset_widget -%}
245
246 {%- block tel_widget -%}
247 {%- set type = type|default('tel') -%}
248 {{ block('form_widget_simple') }}
249 {%- endblock tel_widget -%}
250
251 {%- block color_widget -%}
252 {%- set type = type|default('color') -%}
253 {{ block('form_widget_simple') }}
254 {%- endblock color_widget -%}
255
256 {# Labels #}
257
258 {%- block form_label -%}
259 {% if label is not same as(false) -%}
260 {% if not compound -%}
261 {% set label_attr = label_attr|merge({'for': id}) %}
262 {%- endif -%}
263 {% if required -%}
264 {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
265 {%- endif -%}
266 {% if label is empty -%}
267 {%- if label_format is not empty -%}
268 {% set label = label_format|replace({
269 '%name%': name,
270 '%id%': id,
271 }) %}
272 {%- else -%}
273 {% set label = name|humanize %}
274 {%- endif -%}
275 {%- endif -%}
276 <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>
277 {%- if translation_domain is same as(false) -%}
278 {%- if label_html is same as(false) -%}
279 {{- label -}}
280 {%- else -%}
281 {{- label|raw -}}
282 {%- endif -%}
283 {%- else -%}
284 {%- if label_html is same as(false) -%}
285 {{- label|trans({}, translation_domain) -}}
286 {%- else -%}
287 {{- label|trans({}, translation_domain)|raw -}}
288 {%- endif -%}
289 {%- endif -%}
290 </{{ element|default('label') }}>
291 {%- endif -%}
292 {%- endblock form_label -%}
293
294 {%- block button_label -%}{%- endblock -%}
295
296 {# Rows #}
297
298 {%- block repeated_row -%}
299 {#
300 No need to render the errors here, as all errors are mapped
301 to the first child (see RepeatedTypeValidatorExtension).
302 #}
303 {{- block('form_rows') -}}
304 {%- endblock repeated_row -%}
305
306 {%- block form_row -%}
307 <div class="row">
308 {{- form_label(form) -}}
309 <div>
310 {{- form_widget(form) -}}
311 {%- if errors|length > 0 -%}
312 <div class="message error">
313 {{- form_errors(form) -}}
314 </div>
315 {%- endif -%}
316 </div>
317 </div>
318 {%- endblock form_row -%}
319
320 {%- block button_row -%}
321 <div class="row">
322 {{- form_widget(form) -}}
323 </div>
324 {%- endblock button_row -%}
325
326 {%- block hidden_row -%}
327 {{ form_widget(form) }}
328 {%- endblock hidden_row -%}
329
330 {# Misc #}
331
332 {%- block form -%}
333 {{ form_start(form) }}
334 {{- form_widget(form) -}}
335 {{ form_end(form) }}
336 {%- endblock form -%}
337
338 {%- block form_start -%}
339 {%- do form.setMethodRendered() -%}
340 {% set method = method|upper %}
341 {%- if method in ["GET", "POST"] -%}
342 {% set form_method = method %}
343 {%- else -%}
344 {% set form_method = "POST" %}
345 {%- endif -%}
346 <form name="{{ name }}" method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
347 {%- if form_method != method -%}
348 <input type="hidden" name="_method" value="{{ method }}" />
349 {%- endif -%}
350 {%- if errors|length > 0 -%}
351 <header class="message error">
352 {{- form_errors(form) -}}
353 </header>
354 {%- endif -%}
355 {%- endblock form_start -%}
356
357 {%- block form_end -%}
358 {%- if not render_rest is defined or render_rest -%}
359 {{ form_rest(form) }}
360 {%- endif -%}
361 </form>
362 {%- endblock form_end -%}
363
364 {%- block form_errors -%}
365 {%- if errors|length > 0 -%}
366 <ul>
367 {%- for error in errors -%}
368 <li>{{ error.message }}</li>
369 {%- endfor -%}
370 </ul>
371 {%- endif -%}
372 {%- endblock form_errors -%}
373
374 {%- block form_rest -%}
375 {% for child in form -%}
376 {% if not child.rendered %}
377 {{- form_row(child) -}}
378 {% endif %}
379 {%- endfor -%}
380
381 {% if not form.methodRendered and form is rootform %}
382 {%- do form.setMethodRendered() -%}
383 {% set method = method|upper %}
384 {%- if method in ["GET", "POST"] -%}
385 {% set form_method = method %}
386 {%- else -%}
387 {% set form_method = "POST" %}
388 {%- endif -%}
389
390 {%- if form_method != method -%}
391 <input type="hidden" name="_method" value="{{ method }}" />
392 {%- endif -%}
393 {% endif -%}
394 {% endblock form_rest %}
395
396 {# Support #}
397
398 {%- block form_rows -%}
399 {% for child in form %}
400 {{- form_row(child) -}}
401 {% endfor %}
402 {%- endblock form_rows -%}
403
404 {%- block widget_attributes -%}
405 id="{{ id }}" name="{{ full_name }}"
406 {%- if disabled %} disabled="disabled"{% endif -%}
407 {%- if required %} required="required"{% endif -%}
408 {{ block('attributes') }}
409 {%- endblock widget_attributes -%}
410
411 {%- block widget_container_attributes -%}
412 {%- if id is not empty %}id="{{ id }}"{% endif -%}
413 {{ block('attributes') }}
414 {%- endblock widget_container_attributes -%}
415
416 {%- block button_attributes -%}
417 id="{{ id }}" name="{{ full_name }}"{% if disabled %} disabled="disabled"{% endif -%}
418 {{ block('attributes') }}
419 {%- endblock button_attributes -%}
420
421 {% block attributes -%}
422 {%- for attrname, attrvalue in attr -%}
423 {{- " " -}}
424 {%- if attrname in ['placeholder', 'title'] -%}
425 {{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans({}, translation_domain) }}"
426 {%- elseif attrvalue is same as(true) -%}
427 {{- attrname }}="{{ attrname }}"
428 {%- elseif attrvalue is not same as(false) -%}
429 {{- attrname }}="{{ attrvalue }}"
430 {%- endif -%}
431 {%- endfor -%}
432 {%- endblock attributes -%}