form_admin_fields.html.twig 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. {#
  2. This file is part of the Sonata package.
  3. (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  4. For the full copyright and license information, please view the LICENSE
  5. file that was distributed with this source code.
  6. #}
  7. {# Labels #}
  8. {% block form_label %}
  9. {% spaceless %}
  10. {% set label_class = "" %}
  11. {% if sonata_admin.admin and sonata_admin.admin.getConfigurationPool().getOption('form_type') == 'horizontal' %}
  12. {% set label_class = "control-label col-sm-3" %}
  13. {% else %}
  14. {% set label_class = "control-label" %}
  15. {% endif%}
  16. {#{{ sonata_admin.admin.getConfigurationPool().getOption('form_type') }}#}
  17. {% if label is not sameas(false) %}
  18. {% set label_attr = label_attr|merge({'class': label_attr.class|default('') ~ label_class }) %}
  19. {% if not compound %}
  20. {% set label_attr = label_attr|merge({'for': id}) %}
  21. {% endif %}
  22. {% if required %}
  23. {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
  24. {% endif %}
  25. {% if label is empty %}
  26. {% set label = name|humanize %}
  27. {% endif %}
  28. {% if in_list_checkbox is defined and in_list_checkbox and widget is defined %}
  29. <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>
  30. {{ widget|raw }}
  31. <span>
  32. {% if not sonata_admin.admin %}
  33. {{- label|trans({}, translation_domain) -}}
  34. {% else %}
  35. {{- label|trans({}, sonata_admin.field_description.translationDomain) -}}
  36. {% endif%}
  37. </span>
  38. </label>
  39. {% else %}
  40. <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
  41. {% if not sonata_admin.admin%}
  42. {{- label|trans({}, translation_domain) -}}
  43. {% else %}
  44. {{ sonata_admin.admin.trans(label, {}, sonata_admin.field_description.translationDomain) }}
  45. {% endif %}
  46. </label>
  47. {% endif %}
  48. {% endif %}
  49. {% endspaceless %}
  50. {% endblock form_label %}
  51. {% block widget_container_attributes_choice_widget %}
  52. {% spaceless %}
  53. id="{{ id }}"
  54. {% for attrname,attrvalue in attr %}{{attrname}}="{% if attrname == 'class' %}list-unstyled {% endif%}{{attrvalue}}" {% endfor %}
  55. {% if "class" not in attr %}class="list-unstyled"{%endif %}
  56. {% endspaceless %}
  57. {% endblock %}
  58. {% block choice_widget_expanded %}
  59. {% spaceless %}
  60. <ul {{ block('widget_container_attributes') }}>
  61. {% for child in form %}
  62. <li>
  63. {{ form_widget(child, {'horizontal': false, 'horizontal_input_wrapper_class': ''}) }} {# {'horizontal': false, 'horizontal_input_wrapper_class': ''} needed to avoid MopaBootstrapBundle messing with the DOM #}
  64. {{ form_label(child) }}
  65. </li>
  66. {% endfor %}
  67. </ul>
  68. {% endspaceless %}
  69. {% endblock choice_widget_expanded %}
  70. {% block choice_widget %}
  71. {% spaceless %}
  72. {% if compound %}
  73. <ul {{ block('widget_container_attributes_choice_widget') }}>
  74. {% for child in form %}
  75. <li>
  76. {% set form_widget_content %}
  77. {{ form_widget(child, {'horizontal': false, 'horizontal_input_wrapper_class': ''}) }} {# {'horizontal': false, 'horizontal_input_wrapper_class': ''} needed to avoid MopaBootstrapBundle messing with the DOM #}
  78. {% endset %}
  79. {{ form_label(child, child.vars.label|default(null), { 'in_list_checkbox' : true, 'widget' : form_widget_content } ) }}
  80. </li>
  81. {% endfor %}
  82. </ul>
  83. {% else %}
  84. <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
  85. {% if empty_value is not none %}
  86. <option value="">
  87. {% if not sonata_admin.admin %}
  88. {{- empty_value|trans({}, translation_domain) -}}
  89. {% else %}
  90. {{- empty_value|trans({}, sonata_admin.field_description.translationDomain) -}}
  91. {% endif%}
  92. </option>
  93. {% endif %}
  94. {% if preferred_choices|length > 0 %}
  95. {% set options = preferred_choices %}
  96. {{ block('choice_widget_options') }}
  97. {% if choices|length > 0 %}
  98. <option disabled="disabled">{{ separator }}</option>
  99. {% endif %}
  100. {% endif %}
  101. {% set options = choices %}
  102. {{ block('choice_widget_options') }}
  103. </select>
  104. {% endif %}
  105. {% endspaceless %}
  106. {% endblock choice_widget %}
  107. {% block form_row %}
  108. {% set label_class = "" %}
  109. {% set div_class = "" %}
  110. {% if sonata_admin.admin and sonata_admin.admin.getConfigurationPool().getOption('form_type') == 'horizontal' %}
  111. {% set label_class = "control-label col-sm-3" %}
  112. {% set div_class = "col-sm-9 col-md-9" %}
  113. {% else %}
  114. {% set label_class = "control-label" %}
  115. {% endif%}
  116. {% if sonata_admin is not defined or not sonata_admin_enabled or not sonata_admin.field_description %}
  117. <div class="form-group {% if errors|length > 0%} has-error{% endif %}">
  118. {{ form_label(form, label|default(null)) }}
  119. <div class="{% if label is sameas(false) %}sonata-collection-row-without-label{% endif %}">
  120. {{ form_widget(form, {'horizontal': false, 'horizontal_input_wrapper_class': ''}) }} {# {'horizontal': false, 'horizontal_input_wrapper_class': ''} needed to avoid MopaBootstrapBundle messing with the DOM #}
  121. {% if errors|length > 0 %}
  122. <div class="help-block sonata-ba-field-error-messages">
  123. {{ form_errors(form) }}
  124. </div>
  125. {% endif %}
  126. </div>
  127. </div>
  128. {% else %}
  129. <div class="form-group{% if errors|length > 0%} has-error{%endif%}" id="sonata-ba-field-container-{{ id }}">
  130. {% block label %}
  131. {% if sonata_admin.field_description.options.name is defined %}
  132. {{ form_label(form, sonata_admin.field_description.options.name, { 'attr' : {'class' : label_class} }) }}
  133. {% else %}
  134. {{ form_label(form, label|default(null), { 'attr' : {'class' : label_class} }) }}
  135. {% endif %}
  136. {% endblock %}
  137. {% set has_label = sonata_admin.field_description.options.name is defined or label is not sameas(false) %}
  138. <div class="{{ div_class }} sonata-ba-field sonata-ba-field-{{ sonata_admin.edit }}-{{ sonata_admin.inline }} {% if errors|length > 0 %}sonata-ba-field-error{% endif %} {% if not has_label %}sonata-collection-row-without-label{% endif %}">
  139. {{ form_widget(form, {'horizontal': false, 'horizontal_input_wrapper_class': ''}) }} {# {'horizontal': false, 'horizontal_input_wrapper_class': ''} needed to avoid MopaBootstrapBundle messing with the DOM #}
  140. {% if errors|length > 0 %}
  141. <div class="help-block sonata-ba-field-error-messages">
  142. {{ form_errors(form) }}
  143. </div>
  144. {% endif %}
  145. {% if sonata_admin.field_description.help %}
  146. <span class="help-block sonata-ba-field-help">{{ sonata_admin.admin.trans(sonata_admin.field_description.help, {}, sonata_admin.field_description.translationDomain)|raw }}</span>
  147. {% endif %}
  148. </div>
  149. </div>
  150. {% endif %}
  151. {% endblock form_row %}
  152. {% block collection_widget_row %}
  153. {% spaceless %}
  154. <div class="sonata-collection-row">
  155. {% if allow_delete %}
  156. <a href="#" class="btn sonata-collection-delete"><i class="fa fa-minus-circle"></i></a>
  157. {% endif %}
  158. {{ form_row(child) }}
  159. </div>
  160. {% endspaceless %}
  161. {% endblock %}
  162. {% block collection_widget %}
  163. {% spaceless %}
  164. {% if prototype is defined %}
  165. {% set child = prototype %}
  166. {% set attr = attr|merge({'data-prototype': block('collection_widget_row'), 'data-prototype-name': prototype.vars.name, 'class': attr.class|default('') }) %}
  167. {% endif %}
  168. <div {{ block('widget_container_attributes') }}>
  169. {{ form_errors(form) }}
  170. {% for child in form %}
  171. {{ block('collection_widget_row') }}
  172. {% endfor %}
  173. {{ form_rest(form) }}
  174. {% if allow_add %}
  175. <div><a href="#" class="btn sonata-collection-add"><i class="fa fa-plus-circle"></i></a></div>
  176. {% endif %}
  177. </div>
  178. {% endspaceless %}
  179. {% endblock collection_widget %}
  180. {% block sonata_type_immutable_array_widget %}
  181. {% spaceless %}
  182. <div {{ block('widget_container_attributes') }}>
  183. {{ form_errors(form) }}
  184. {% for key, child in form %}
  185. {{ block('sonata_type_immutable_array_widget_row') }}
  186. {% endfor %}
  187. {{ form_rest(form) }}
  188. </div>
  189. {% endspaceless %}
  190. {% endblock sonata_type_immutable_array_widget %}
  191. {% block sonata_type_immutable_array_widget_row %}
  192. {% spaceless %}
  193. <div class="form-group{% if errors|length > 0%} error{%endif%}" id="sonata-ba-field-container-{{ id }}-{{ key }}">
  194. {{ form_label(child) }}
  195. {% set div_class = "" %}
  196. {% if sonata_admin.admin and sonata_admin.admin.getConfigurationPool().getOption('form_type') == 'horizontal' %}
  197. {% set div_class = "col-sm-9 col-md-9" %}
  198. {% endif%}
  199. <div class="{{ div_class }} sonata-ba-field sonata-ba-field-{{ sonata_admin.edit }}-{{ sonata_admin.inline }} {% if errors|length > 0 %}sonata-ba-field-error{% endif %}">
  200. {{ form_widget(child, {'horizontal': false, 'horizontal_input_wrapper_class': ''}) }} {# {'horizontal': false, 'horizontal_input_wrapper_class': ''} needed to avoid MopaBootstrapBundle messing with the DOM #}
  201. </div>
  202. {% if errors|length > 0 %}
  203. <div class="help-block sonata-ba-field-error-messages">
  204. {{ form_errors(child) }}
  205. </div>
  206. {% endif %}
  207. </div>
  208. {% endspaceless %}
  209. {% endblock %}