form_admin_fields.html.twig 4.8 KB

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