form_admin_fields.html.twig 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. {% extends 'SonataAdminBundle:Form:silex_form_div_layout.html.twig' %}
  8. {# Labels #}
  9. {% block generic_label %}
  10. {% spaceless %}
  11. {% if required %}
  12. {% set attr = attr|merge({'class': attr.class|default('') ~ ' required'}) %}
  13. {% endif %}
  14. {% if in_list_checkbox is defined and in_list_checkbox and widget is defined %}
  15. <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>
  16. {{ widget|raw }}
  17. <span>
  18. {% if not sonata_admin.admin%}
  19. {{- label -}}
  20. {% else %}
  21. {{- label|trans({}, sonata_admin.admin.translationDomain) -}}
  22. {% endif%}
  23. </span>
  24. </label>
  25. {% else %}
  26. <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>
  27. {% if not sonata_admin.admin%}
  28. {{ label }}
  29. {% else %}
  30. {{ label|trans({}, sonata_admin.admin.translationDomain) }}
  31. {% endif%}
  32. {{ required ? '*' : '' }}
  33. </label>
  34. {% endif %}
  35. {% endspaceless %}
  36. {% endblock %}
  37. {% block widget_container_attributes_choice_widget %}
  38. {% spaceless %}
  39. id="{{ id }}"
  40. {% for attrname,attrvalue in attr %}{{attrname}}="{% if attrname == 'class' %}inputs-list {% endif%}{{attrvalue}}" {% endfor %}
  41. {% endspaceless %}
  42. {% endblock %}
  43. {% block choice_widget %}
  44. {% spaceless %}
  45. {% if expanded %}
  46. <ul {{ block('widget_container_attributes') }}>
  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 %}