form_admin_fields.html.twig 4.9 KB

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