form_admin_fields.html.twig 9.2 KB

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