form_admin_fields.html.twig 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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" }) %}
  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. {{ required ? '*' : '' }}
  40. </label>
  41. {% endif %}
  42. {% endif %}
  43. {% endspaceless %}
  44. {% endblock form_label %}
  45. {% block widget_container_attributes_choice_widget %}
  46. {% spaceless %}
  47. id="{{ id }}"
  48. {% for attrname,attrvalue in attr %}{{attrname}}="{% if attrname == 'class' %}unstyled {% endif%}{{attrvalue}}" {% endfor %}
  49. {% if "class" not in attr %}class="unstyled"{%endif %}
  50. {% endspaceless %}
  51. {% endblock %}
  52. {% block choice_widget_expanded %}
  53. {% spaceless %}
  54. <ul {{ block('widget_container_attributes') }}>
  55. {% for child in form %}
  56. <li>
  57. {{ form_widget(child) }}
  58. {{ form_label(child) }}
  59. </li>
  60. {% endfor %}
  61. </ul>
  62. {% endspaceless %}
  63. {% endblock choice_widget_expanded %}
  64. {% block choice_widget %}
  65. {% spaceless %}
  66. {% if expanded %}
  67. <ul {{ block('widget_container_attributes_choice_widget') }}>
  68. {% for child in form %}
  69. <li>
  70. {{ form_label(child, child.vars.label|default(null), { 'in_list_checkbox' : true, 'widget' : form_widget(child) } ) }}
  71. </li>
  72. {% endfor %}
  73. </ul>
  74. {% else %}
  75. <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
  76. {% if empty_value is not none %}
  77. <option value="">{{ empty_value|trans }}</option>
  78. {% endif %}
  79. {% if preferred_choices|length > 0 %}
  80. {% set options = preferred_choices %}
  81. {{ block('choice_widget_options') }}
  82. {% if choices|length > 0 %}
  83. <option disabled="disabled">{{ separator }}</option>
  84. {% endif %}
  85. {% endif %}
  86. {% set options = choices %}
  87. {{ block('choice_widget_options') }}
  88. </select>
  89. {% endif %}
  90. {% endspaceless %}
  91. {% endblock choice_widget %}
  92. {% block form_row %}
  93. {% if sonata_admin is not defined or not sonata_admin_enabled or not sonata_admin.field_description %}
  94. <div class="control-group {% if errors|length > 0%} error{% endif %}">
  95. {{ form_label(form, label|default(null)) }}
  96. <div class="controls">
  97. {{ form_widget(form) }}
  98. {% if errors|length > 0 %}
  99. <div class="help-inline sonata-ba-field-error-messages">
  100. {{ form_errors(form) }}
  101. </div>
  102. {% endif %}
  103. </div>
  104. </div>
  105. {% else %}
  106. <div class="control-group{% if errors|length > 0%} error{%endif%}" id="sonata-ba-field-container-{{ id }}">
  107. {% block label %}
  108. {% if sonata_admin.field_description.options.name is defined %}
  109. {{ form_label(form, sonata_admin.field_description.options.name, { 'attr' : {'class' : 'control-label'} }) }}
  110. {% else %}
  111. {{ form_label(form, label|default(null), { 'attr' : {'class' : 'control-label'} }) }}
  112. {% endif %}
  113. {% endblock %}
  114. <div class="controls sonata-ba-field sonata-ba-field-{{ sonata_admin.edit }}-{{ sonata_admin.inline }} {% if errors|length > 0 %}sonata-ba-field-error{% endif %}">
  115. {{ form_widget(form) }}
  116. {% if errors|length > 0 %}
  117. <div class="help-inline sonata-ba-field-error-messages">
  118. {{ form_errors(form) }}
  119. </div>
  120. {% endif %}
  121. {% if sonata_admin.field_description.help %}
  122. <span class="help-block sonata-ba-field-help">{{ sonata_admin.admin.trans(sonata_admin.field_description.help, {}, sonata_admin.field_description.translationDomain)|raw }}</span>
  123. {% endif %}
  124. </div>
  125. </div>
  126. {% endif %}
  127. {% endblock form_row %}
  128. {% block collection_widget_row %}
  129. {% spaceless %}
  130. <div class="sonata-collection-row">
  131. {% if allow_delete %}
  132. <a href="#" class="btn sonata-collection-delete"><i class="icon-remove"></i></a>
  133. {% endif %}
  134. {{ form_row(child) }}
  135. </div>
  136. {% endspaceless %}
  137. {% endblock %}
  138. {% block collection_widget %}
  139. {% spaceless %}
  140. {% if prototype is defined %}
  141. {% set child = prototype %}
  142. {% set attr = attr|merge({'data-prototype': block('collection_widget_row'), 'class': attr.class|default('') ~ ' controls' }) %}
  143. {% endif %}
  144. <div {{ block('widget_container_attributes') }}>
  145. {{ form_errors(form) }}
  146. {% for child in form %}
  147. {{ block('collection_widget_row') }}
  148. {% endfor %}
  149. {{ form_rest(form) }}
  150. {% if allow_add %}
  151. <div><a href="#" class="btn sonata-collection-add"><i class="icon-plus"></i></a></div>
  152. {% endif %}
  153. </div>
  154. {% endspaceless %}
  155. {% endblock collection_widget %}
  156. {% block sonata_type_immutable_array_widget %}
  157. {% spaceless %}
  158. <div class="controls">
  159. <div {{ block('widget_container_attributes') }}>
  160. {{ form_errors(form) }}
  161. {% for key, child in form %}
  162. {{ block('sonata_type_immutable_array_widget_row') }}
  163. {% endfor %}
  164. {{ form_rest(form) }}
  165. </div>
  166. </div>
  167. {% endspaceless %}
  168. {% endblock sonata_type_immutable_array_widget %}
  169. {% block sonata_type_immutable_array_widget_row %}
  170. {% spaceless %}
  171. <div class="control-group{% if errors|length > 0%} error{%endif%}" id="sonata-ba-field-container-{{ id }}-{{ key }}">
  172. {{ form_label(child) }}
  173. <div class="controls sonata-ba-field sonata-ba-field-{{ sonata_admin.edit }}-{{ sonata_admin.inline }} {% if errors|length > 0 %}sonata-ba-field-error{% endif %}">
  174. {{ form_widget(child) }}
  175. </div>
  176. {% if errors|length > 0 %}
  177. <div class="help-inline sonata-ba-field-error-messages">
  178. {{ form_errors(child) }}
  179. </div>
  180. {% endif %}
  181. </div>
  182. {% endspaceless %}
  183. {% endblock %}