form_raw_layout.html.twig 17 KB

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