form_admin_fields.html.twig 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_attr = label_attr|merge({'class': label_attr.class|default('') ~ " control-label" }) %}
  11. {% if not compound %}
  12. {% set label_attr = label_attr|merge({'for': id}) %}
  13. {% endif %}
  14. {% if required %}
  15. {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
  16. {% endif %}
  17. {% if label is empty %}
  18. {% set label = name|humanize %}
  19. {% endif %}
  20. {% if in_list_checkbox is defined and in_list_checkbox and widget is defined %}
  21. <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>
  22. {{ widget|raw }}
  23. <span>
  24. {% if not sonata_admin.admin%}
  25. {{- label|trans({}, translation_domain) -}}
  26. {% else %}
  27. {{- label|trans({}, sonata_admin.admin.translationDomain) -}}
  28. {% endif%}
  29. </span>
  30. </label>
  31. {% else %}
  32. <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
  33. {% if not sonata_admin.admin%}
  34. {{- label|trans({}, translation_domain) -}}
  35. {% else %}
  36. {{- label|trans({}, sonata_admin.admin.translationDomain) -}}
  37. {% endif%}
  38. {{ required ? '*' : '' }}
  39. </label>
  40. {% endif %}
  41. {% endspaceless %}
  42. {% endblock form_label %}
  43. {% block widget_container_attributes_choice_widget %}
  44. {% spaceless %}
  45. id="{{ id }}"
  46. {% for attrname,attrvalue in attr %}{{attrname}}="{% if attrname == 'class' %}unstyled {% endif%}{{attrvalue}}" {% endfor %}
  47. {% if "class" not in attr %}class="unstyled"{%endif %}
  48. {% endspaceless %}
  49. {% endblock %}
  50. {% block choice_widget_expanded %}
  51. {% spaceless %}
  52. <ul {{ block('widget_container_attributes') }}>
  53. {% for child in form %}
  54. <li>
  55. {{ form_widget(child) }}
  56. {{ form_label(child) }}
  57. </li>
  58. {% endfor %}
  59. </ul>
  60. {% endspaceless %}
  61. {% endblock choice_widget_expanded %}
  62. {% block choice_widget %}
  63. {% spaceless %}
  64. {% if expanded %}
  65. <ul {{ block('widget_container_attributes_choice_widget') }}>
  66. {% for child in form %}
  67. <li>
  68. {{ form_label(child, child.vars.label|default(null), { 'in_list_checkbox' : true, 'widget' : form_widget(child) } ) }}
  69. </li>
  70. {% endfor %}
  71. </ul>
  72. {% else %}
  73. <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
  74. {% if empty_value is not none %}
  75. <option value="">{{ empty_value|trans }}</option>
  76. {% endif %}
  77. {% if preferred_choices|length > 0 %}
  78. {% set options = preferred_choices %}
  79. {{ block('widget_choice_options') }}
  80. {% if choices|length > 0 %}
  81. <option disabled="disabled">{{ separator }}</option>
  82. {% endif %}
  83. {% endif %}
  84. {% set options = choices %}
  85. {{ block('widget_choice_options') }}
  86. </select>
  87. {% endif %}
  88. {% endspaceless %}
  89. {% endblock choice_widget %}
  90. {% block field_row %}
  91. {% if sonata_admin is not defined or not sonata_admin_enabled or not sonata_admin.field_description %}
  92. {{ form_row(form) }}
  93. {% else %}
  94. <div class="control-group{% if errors|length > 0%} error{%endif%}" id="sonata-ba-field-container-{{ id }}">
  95. {% block label %}
  96. {% if sonata_admin.field_description.options.name is defined %}
  97. {{ form_label(form, sonata_admin.field_description.options.name, { 'attr' : {'class' : 'control-label'} }) }}
  98. {% else %}
  99. {{ form_label(form, label|default(null), { 'attr' : {'class' : 'control-label'} }) }}
  100. {% endif %}
  101. {% endblock %}
  102. <div class="controls sonata-ba-field sonata-ba-field-{{ sonata_admin.edit }}-{{ sonata_admin.inline }} {% if errors|length > 0 %}sonata-ba-field-error{% endif %}">
  103. {{ form_widget(form) }}
  104. {% if errors|length > 0 %}
  105. <div class="help-inline sonata-ba-field-error-messages">
  106. {{ form_errors(form) }}
  107. </div>
  108. {% endif %}
  109. {% if sonata_admin.field_description.help %}
  110. <span class="help-block sonata-ba-field-help">{{ sonata_admin.field_description.help }}</span>
  111. {% endif %}
  112. </div>
  113. </div>
  114. {% endif %}
  115. {% endblock field_row %}
  116. {% block collection_widget_row %}
  117. {% spaceless %}
  118. <div class="sonata-collection-row">
  119. {% if allow_delete %}
  120. <a href="#" class="sonata-collection-delete"></a>
  121. {% endif %}
  122. {{ form_row(child) }}
  123. </div>
  124. {% endspaceless %}
  125. {% endblock %}
  126. {% block collection_widget %}
  127. {% spaceless %}
  128. {% if prototype is defined %}
  129. {% set child = prototype %}
  130. {% set attr = attr|merge({'data-prototype': block('collection_widget_row') }) %}
  131. {% endif %}
  132. <div {{ block('widget_container_attributes') }}>
  133. {{ form_errors(form) }}
  134. {% for child in form %}
  135. {{ block('collection_widget_row') }}
  136. {% endfor %}
  137. {{ form_rest(form) }}
  138. {% if allow_add %}
  139. <div><a href="#" class="sonata-collection-add"></a></div>
  140. {% endif %}
  141. </div>
  142. {% endspaceless %}
  143. {% endblock collection_widget %}