vendor/symfony/twig-bridge/Resources/views/Form/form_div_layout.html.twig line 31

Open in your IDE?
  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. <div{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
  331. {{- form_widget(form) -}}
  332. </div>
  333. {%- endblock button_row -%}
  334. {%- block hidden_row -%}
  335. {{ form_widget(form) }}
  336. {%- endblock hidden_row -%}
  337. {# Misc #}
  338. {%- block form -%}
  339. {{ form_start(form) }}
  340. {{- form_widget(form) -}}
  341. {{ form_end(form) }}
  342. {%- endblock form -%}
  343. {%- block form_start -%}
  344. {%- do form.setMethodRendered() -%}
  345. {% set method = method|upper %}
  346. {%- if method in ["GET", "POST"] -%}
  347. {% set form_method = method %}
  348. {%- else -%}
  349. {% set form_method = "POST" %}
  350. {%- endif -%}
  351. <form{% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{{ block('attributes') }}{% if multipart %} enctype="multipart/form-data"{% endif %}>
  352. {%- if form_method != method -%}
  353. <input type="hidden" name="_method" value="{{ method }}" />
  354. {%- endif -%}
  355. {%- endblock form_start -%}
  356. {%- block form_end -%}
  357. {%- if not render_rest is defined or render_rest -%}
  358. {{ form_rest(form) }}
  359. {%- endif -%}
  360. </form>
  361. {%- endblock form_end -%}
  362. {%- block form_errors -%}
  363. {%- if errors|length > 0 -%}
  364. <ul>
  365. {%- for error in errors -%}
  366. <li>{{ error.message }}</li>
  367. {%- endfor -%}
  368. </ul>
  369. {%- endif -%}
  370. {%- endblock form_errors -%}
  371. {%- block form_rest -%}
  372. {% for child in form -%}
  373. {% if not child.rendered %}
  374. {{- form_row(child) -}}
  375. {% endif %}
  376. {%- endfor -%}
  377. {% if not form.methodRendered and form is rootform %}
  378. {%- do form.setMethodRendered() -%}
  379. {% set method = method|upper %}
  380. {%- if method in ["GET", "POST"] -%}
  381. {% set form_method = method %}
  382. {%- else -%}
  383. {% set form_method = "POST" %}
  384. {%- endif -%}
  385. {%- if form_method != method -%}
  386. <input type="hidden" name="_method" value="{{ method }}" />
  387. {%- endif -%}
  388. {% endif -%}
  389. {% endblock form_rest %}
  390. {# Support #}
  391. {%- block form_rows -%}
  392. {% for child in form|filter(child => not child.rendered) %}
  393. {{- form_row(child) -}}
  394. {% endfor %}
  395. {%- endblock form_rows -%}
  396. {%- block widget_attributes -%}
  397. id="{{ id }}" name="{{ full_name }}"
  398. {%- if disabled %} disabled="disabled"{% endif -%}
  399. {%- if required %} required="required"{% endif -%}
  400. {{ block('attributes') }}
  401. {%- endblock widget_attributes -%}
  402. {%- block widget_container_attributes -%}
  403. {%- if id is not empty %}id="{{ id }}"{% endif -%}
  404. {{ block('attributes') }}
  405. {%- endblock widget_container_attributes -%}
  406. {%- block button_attributes -%}
  407. id="{{ id }}" name="{{ full_name }}"{% if disabled %} disabled="disabled"{% endif -%}
  408. {{ block('attributes') }}
  409. {%- endblock button_attributes -%}
  410. {% block attributes -%}
  411. {%- for attrname, attrvalue in attr -%}
  412. {{- " " -}}
  413. {%- if attrname in ['placeholder', 'title'] -%}
  414. {{- attrname }}="{{ translation_domain is same as(false) or attrvalue is null ? attrvalue : attrvalue|trans(attr_translation_parameters, translation_domain) }}"
  415. {%- elseif attrvalue is same as(true) -%}
  416. {{- attrname }}="{{ attrname }}"
  417. {%- elseif attrvalue is not same as(false) -%}
  418. {{- attrname }}="{{ attrvalue }}"
  419. {%- endif -%}
  420. {%- endfor -%}
  421. {%- endblock attributes -%}