form_admin_fields.html.twig 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. {% if "class" not in attr %}class="inputs-list"{%endif %}
  42. {% endspaceless %}
  43. {% endblock %}
  44. {% block choice_widget %}
  45. {% spaceless %}
  46. {% if expanded %}
  47. <ul {{ block('widget_container_attributes_choice_widget') }}>
  48. {% for child in form %}
  49. <li>
  50. {{ form_label(child, null, { 'in_list_checkbox' : true, 'widget' : form_widget(child) } ) }}
  51. </li>
  52. {% endfor %}
  53. </ul>
  54. {% else %}
  55. <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
  56. {% if empty_value is not none %}
  57. <option value="">{{ empty_value|trans }}</option>
  58. {% endif %}
  59. {% if preferred_choices|length > 0 %}
  60. {% set options = preferred_choices %}
  61. {{ block('widget_choice_options') }}
  62. {% if choices|length > 0 %}
  63. <option disabled="disabled">{{ separator }}</option>
  64. {% endif %}
  65. {% endif %}
  66. {% set options = choices %}
  67. {{ block('widget_choice_options') }}
  68. </select>
  69. {% endif %}
  70. {% endspaceless %}
  71. {% endblock choice_widget %}
  72. {% block field_row %}
  73. {% if sonata_admin is not defined or not sonata_admin_enabled or not sonata_admin.field_description %}
  74. {{ parent() }}
  75. {% else %}
  76. <div class="clearfix{% if errors|length > 0%} error{%endif%}" id="sonata-ba-field-container-{{ id }}">
  77. {% block label %}
  78. {% if sonata_admin.field_description.options.name is defined %}
  79. {{ form_label(form, sonata_admin.field_description.options.name) }}
  80. {% else %}
  81. {{ form_label(form) }}
  82. {% endif %}
  83. {% endblock %}
  84. <div class="input sonata-ba-field sonata-ba-field-{{ sonata_admin.edit }}-{{ sonata_admin.inline }} {% if errors|length > 0 %}sonata-ba-field-error{% endif %}">
  85. {{ form_widget(form) }}
  86. {% if sonata_admin.field_description.help %}
  87. <span class="help-block sonata-ba-field-help">{{ sonata_admin.field_description.help }}</span>
  88. {% endif %}
  89. {% if errors|length > 0 %}
  90. <div class="sonata-ba-field-error-messages">
  91. {{ form_errors(form) }}
  92. </div>
  93. {% endif %}
  94. </div>
  95. </div>
  96. {% endif %}
  97. {% endblock field_row %}