Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.62 KB | None | 0 0
  1. {% use "form_div_layout.html.twig" %}
  2.  
  3. {# Widgets #}
  4.  
  5. {% block form_widget_simple -%}
  6. {% if type is not defined or type not in ['file', 'hidden'] %}
  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 button_widget -%}
  18. {% set attr = attr|merge({class: (attr.class|default('btn-default') ~ ' btn')|trim}) %}
  19. {{- parent() -}}
  20. {%- endblock %}
  21.  
  22. {% block money_widget -%}
  23. <div class="input-group">
  24. {% set append = money_pattern starts with '{{' %}
  25. {% if not append %}
  26. <span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
  27. {% endif %}
  28. {{- block('form_widget_simple') -}}
  29. {% if append %}
  30. <span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
  31. {% endif %}
  32. </div>
  33. {%- endblock money_widget %}
  34.  
  35. {% block percent_widget -%}
  36. <div class="input-group">
  37. {{- block('form_widget_simple') -}}
  38. <span class="input-group-addon">%</span>
  39. </div>
  40. {%- endblock percent_widget %}
  41.  
  42. {% block datetime_widget -%}
  43. {% if widget == 'single_text' %}
  44. {{- block('form_widget_simple') -}}
  45. {% else -%}
  46. {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
  47. <div {{ block('widget_container_attributes') }}>
  48. {{- form_errors(form.date) -}}
  49. {{- form_errors(form.time) -}}
  50. {{- form_widget(form.date, { datetime: true } ) -}}
  51. {{- form_widget(form.time, { datetime: true } ) -}}
  52. </div>
  53. {%- endif %}
  54. {%- endblock datetime_widget %}
  55.  
  56. {% block date_widget -%}
  57. {% if widget == 'single_text' %}
  58. {{- block('form_widget_simple') -}}
  59. {% else -%}
  60. {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
  61. {% if datetime is not defined or not datetime -%}
  62. <div {{ block('widget_container_attributes') -}}>
  63. {%- endif %}
  64. {{- date_pattern|replace({
  65. '{{ year }}': form_widget(form.year),
  66. '{{ month }}': form_widget(form.month),
  67. '{{ day }}': form_widget(form.day),
  68. })|raw -}}
  69. {% if datetime is not defined or not datetime -%}
  70. </div>
  71. {%- endif -%}
  72. {% endif %}
  73. {%- endblock date_widget %}
  74.  
  75. {% block time_widget -%}
  76. {% if widget == 'single_text' %}
  77. {{- block('form_widget_simple') -}}
  78. {% else -%}
  79. {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
  80. {% if datetime is not defined or false == datetime -%}
  81. <div {{ block('widget_container_attributes') -}}>
  82. {%- endif -%}
  83. {{- form_widget(form.hour) }}{% if with_minutes %}:{{ form_widget(form.minute) }}{% endif %}{% if with_seconds %}:{{ form_widget(form.second) }}{% endif %}
  84. {% if datetime is not defined or false == datetime -%}
  85. </div>
  86. {%- endif -%}
  87. {% endif %}
  88. {%- endblock time_widget %}
  89.  
  90. {%- block dateinterval_widget -%}
  91. {%- if widget == 'single_text' -%}
  92. {{- block('form_widget_simple') -}}
  93. {%- else -%}
  94. {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
  95. <div {{ block('widget_container_attributes') }}>
  96. {{- form_errors(form) -}}
  97. <div class="table-responsive">
  98. <table class="table {{ table_class|default('table-bordered table-condensed table-striped') }}">
  99. <thead>
  100. <tr>
  101. {%- if with_years %}<th>{{ form_label(form.years) }}</th>{% endif -%}
  102. {%- if with_months %}<th>{{ form_label(form.months) }}</th>{% endif -%}
  103. {%- if with_weeks %}<th>{{ form_label(form.weeks) }}</th>{% endif -%}
  104. {%- if with_days %}<th>{{ form_label(form.days) }}</th>{% endif -%}
  105. {%- if with_hours %}<th>{{ form_label(form.hours) }}</th>{% endif -%}
  106. {%- if with_minutes %}<th>{{ form_label(form.minutes) }}</th>{% endif -%}
  107. {%- if with_seconds %}<th>{{ form_label(form.seconds) }}</th>{% endif -%}
  108. </tr>
  109. </thead>
  110. <tbody>
  111. <tr>
  112. {%- if with_years %}<td>{{ form_widget(form.years) }}</td>{% endif -%}
  113. {%- if with_months %}<td>{{ form_widget(form.months) }}</td>{% endif -%}
  114. {%- if with_weeks %}<td>{{ form_widget(form.weeks) }}</td>{% endif -%}
  115. {%- if with_days %}<td>{{ form_widget(form.days) }}</td>{% endif -%}
  116. {%- if with_hours %}<td>{{ form_widget(form.hours) }}</td>{% endif -%}
  117. {%- if with_minutes %}<td>{{ form_widget(form.minutes) }}</td>{% endif -%}
  118. {%- if with_seconds %}<td>{{ form_widget(form.seconds) }}</td>{% endif -%}
  119. </tr>
  120. </tbody>
  121. </table>
  122. </div>
  123. {%- if with_invert %}{{ form_widget(form.invert) }}{% endif -%}
  124. </div>
  125. {%- endif -%}
  126. {%- endblock dateinterval_widget -%}
  127.  
  128. {% block choice_widget_collapsed -%}
  129. {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) %}
  130. {{- parent() -}}
  131. {%- endblock %}
  132.  
  133. {% block choice_widget_expanded -%}
  134. {% if '-inline' in label_attr.class|default('') -%}
  135. {%- for child in form %}
  136. {{- form_widget(child, {
  137. parent_label_class: label_attr.class|default(''),
  138. translation_domain: choice_translation_domain,
  139. }) -}}
  140. {% endfor -%}
  141. {%- else -%}
  142. <div {{ block('widget_container_attributes') }}>
  143. {%- for child in form %}
  144. {{- form_widget(child, {
  145. parent_label_class: label_attr.class|default(''),
  146. translation_domain: choice_translation_domain,
  147. }) -}}
  148. {% endfor -%}
  149. </div>
  150. {%- endif %}
  151. {%- endblock choice_widget_expanded %}
  152.  
  153. {% block checkbox_widget -%}
  154. {%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
  155. {% if 'checkbox-inline' in parent_label_class %}
  156. {{- form_label(form, null, { widget: parent() }) -}}
  157. {% else -%}
  158. <div class="checkbox">
  159. {{- form_label(form, null, { widget: parent() }) -}}
  160. </div>
  161. {%- endif %}
  162. {%- endblock checkbox_widget %}
  163.  
  164. {% block radio_widget -%}
  165. {%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
  166. {% if 'radio-inline' in parent_label_class %}
  167. {{- form_label(form, null, { widget: parent() }) -}}
  168. {% else -%}
  169. <div class="radio">
  170. {{- form_label(form, null, { widget: parent() }) -}}
  171. </div>
  172. {%- endif %}
  173. {%- endblock radio_widget %}
  174.  
  175. {# Labels #}
  176.  
  177. {% block form_label -%}
  178. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-control-label')|trim}) -%}
  179. {{- parent() -}}
  180. {%- endblock form_label %}
  181.  
  182. {% block choice_label -%}
  183. {# remove the checkbox-inline and radio-inline class, it's only useful for embed labels #}
  184. {%- set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': ''})|trim}) -%}
  185. {{- block('form_label') -}}
  186. {% endblock %}
  187.  
  188. {% block checkbox_label -%}
  189. {{- block('checkbox_radio_label') -}}
  190. {%- endblock checkbox_label %}
  191.  
  192. {% block radio_label -%}
  193. {{- block('checkbox_radio_label') -}}
  194. {%- endblock radio_label %}
  195.  
  196. {% block checkbox_radio_label %}
  197. {# Do not display the label if widget is not defined in order to prevent double label rendering #}
  198. {% if widget is defined %}
  199. {% if required %}
  200. {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %}
  201. {% endif %}
  202. {% if parent_label_class is defined %}
  203. {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|trim}) %}
  204. {% endif %}
  205. {% if label is not same as(false) and label is empty %}
  206. {%- if label_format is not empty -%}
  207. {% set label = label_format|replace({
  208. '%name%': name,
  209. '%id%': id,
  210. }) %}
  211. {%- else -%}
  212. {% set label = name|humanize %}
  213. {%- endif -%}
  214. {% endif %}
  215. <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
  216. {{- widget|raw }} {{ label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}}
  217. </label>
  218. {% endif %}
  219. {% endblock checkbox_radio_label %}
  220.  
  221. {# Rows #}
  222.  
  223. {% block form_row -%}
  224. <div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-danger{% endif %}">
  225. {{- form_label(form) -}}
  226. {{- form_widget(form) -}}
  227. {{- form_errors(form) -}}
  228. </div>
  229. {%- endblock form_row %}
  230.  
  231. {% block button_row -%}
  232. <div class="form-group">
  233. {{- form_widget(form) -}}
  234. </div>
  235. {%- endblock button_row %}
  236.  
  237. {% block choice_row -%}
  238. {% set force_error = true %}
  239. {{- block('form_row') }}
  240. {%- endblock choice_row %}
  241.  
  242. {% block date_row -%}
  243. {% set force_error = true %}
  244. {{- block('form_row') }}
  245. {%- endblock date_row %}
  246.  
  247. {% block time_row -%}
  248. {% set force_error = true %}
  249. {{- block('form_row') }}
  250. {%- endblock time_row %}
  251.  
  252. {% block datetime_row -%}
  253. {% set force_error = true %}
  254. {{- block('form_row') }}
  255. {%- endblock datetime_row %}
  256.  
  257. {% block checkbox_row -%}
  258. <div class="form-group{% if not valid %} has-danger{% endif %}">
  259. {{- form_widget(form) -}}
  260. {{- form_errors(form) -}}
  261. </div>
  262. {%- endblock checkbox_row %}
  263.  
  264. {% block radio_row -%}
  265. <div class="form-group{% if not valid %} has-danger{% endif %}">
  266. {{- form_widget(form) -}}
  267. {{- form_errors(form) -}}
  268. </div>
  269. {%- endblock radio_row %}
  270.  
  271. {# Errors #}
  272.  
  273. {% block form_errors -%}
  274. {% if errors|length > 0 -%}
  275. {% if form.parent %}<div class="form-control-feedback">{% else %}<div class="alert alert-danger">{% endif %}
  276. <ul class="list-unstyled">
  277. {%- for error in errors -%}
  278. <li>{{ error.message }}</li>
  279. {%- endfor -%}
  280. </ul>
  281. {% if form.parent %}</div>{% else %}</div>{% endif %}
  282. {%- endif %}
  283. {%- endblock form_errors %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement