You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

form_theme.html.twig 13KB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
  2. {% use '@EasyAdmin/crud/form_theme.html.twig' %}
  3. {% block form_row %}
  4. {% set row_attr = row_attr|merge({
  5. class: row_attr.class|default('') ~ ' form-group'
  6. }) %}
  7. <div {% with { attr: row_attr } %}{{ block('attributes') }}{% endwith %}>
  8. {{- form_label(form) -}}
  9. <div class="form-widget">
  10. {% set has_prepend_html = ea.field.prepend_html|default(null) is not null %}
  11. {% set has_append_html = ea.field.append_html|default(null) is not null %}
  12. {% set has_input_groups = has_prepend_html or has_append_html %}
  13. {% if has_input_groups %}
  14. <div class="input-group">{% endif %}
  15. {% if has_prepend_html %}
  16. <div class="input-group-prepend">
  17. <span class="input-group-text">{{ ea.field.prepend_html|raw }}</span>
  18. </div>
  19. {% endif %}
  20. {{ form_widget(form) }}
  21. {% if has_append_html %}
  22. <div class="input-group-append">
  23. <span class="input-group-text">{{ ea.field.append_html|raw }}</span>
  24. </div>
  25. {% endif %}
  26. {% if has_input_groups %}</div>{% endif %}
  27. {% set nullable_fields_fqcn = [
  28. 'EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField',
  29. 'EasyCorp\Bundle\EasyAdminBundle\Field\DateField',
  30. 'EasyCorp\Bundle\EasyAdminBundle\Field\TimeField',
  31. ] %}
  32. {% if form.vars.ea_crud_form.ea_field.fieldFqcn|default(false) in nullable_fields_fqcn and ea.field.nullable|default(false) %}
  33. <div class="nullable-control">
  34. <label>
  35. <input type="checkbox" {% if data is null %}checked="checked"{% endif %}>
  36. {{ 'label.nullable_field'|trans({}, 'EasyAdminBundle') }}
  37. </label>
  38. </div>
  39. {% endif %}
  40. {% set help_message = name|lc_trans_admin_help(form.parent.vars.data) %}
  41. {% if help_message != '' %}
  42. <small class="form-help">{{ help_message }}</small>
  43. {% endif %}
  44. {{- form_errors(form) -}}
  45. </div>
  46. </div>
  47. {% endblock form_row %}
  48. {% block form_label -%}
  49. {% if label is same as(false) -%}
  50. <label>{# the empty <label> is needed to not break the form design #}</label>
  51. {%- else -%}
  52. {%- if compound is defined and compound -%}
  53. {%- set element = 'legend' -%}
  54. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-label')|trim}) -%}
  55. {%- else -%}
  56. {%- set label_attr = label_attr|merge({for: id, class: (label_attr.class|default('') ~ ' form-control-label')|trim}) -%}
  57. {%- endif -%}
  58. {% if required -%}
  59. {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %}
  60. {%- endif -%}
  61. {% if label is empty -%}
  62. {%- if label_format is not empty -%}
  63. {% set label = label_format|replace({
  64. '%name%': name,
  65. '%id%': id,
  66. }) %}
  67. {%- else -%}
  68. {# {% set label = name|humanize %} #}
  69. {%- endif -%}
  70. {%- endif -%}
  71. {# <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ (translation_domain is same as(false)) ? label : label|lower|lc_trans_admin_field(ea.getEntity().getFqcn()) }}</{{ element|default('label') }}> #}
  72. <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ (label is not empty and '.' in label) ? label|trans({}, 'admin') : name|lc_trans_admin_field(form.parent.vars.data) }}</{{ element|default('label') }}>
  73. {%- endif -%}
  74. {%- endblock form_label %}
  75. {% block gallery_manager_row %}
  76. {{ block('collection_row') }}
  77. {% endblock gallery_manager_row %}
  78. {% block gallery_manager_widget %}
  79. {{ block('collection_widget') }}
  80. {% endblock gallery_manager_widget %}
  81. {% block collection_row %}
  82. {% if prototype is defined and not prototype.rendered %}
  83. {% set row_attr = row_attr|merge({ 'data-prototype': form_row(prototype) }) %}
  84. {% endif %}
  85. {% set row_attr = row_attr|merge({
  86. 'data-entry-is-complex': form.vars.ea_crud_form.ea_field and form.vars.ea_crud_form.ea_field.customOptions.get('entryIsComplex') ? 'true' : 'false',
  87. 'data-allow-add': allow_add ? 'true' : 'false',
  88. 'data-allow-delete': allow_delete ? 'true' : 'false',
  89. 'data-num-items': form.children|length,
  90. 'data-form-type-name-placeholder': prototype is defined ? prototype.vars.name : '',
  91. }) %}
  92. {{ block('form_row') }}
  93. {% endblock collection_row %}
  94. {% block collection_widget %}
  95. {{ block('form_widget') }}
  96. {% if allow_add|default(false) %}
  97. <button type="button" class="btn btn-link field-collection-add">
  98. <i class="fa fa-plus pr-1"></i>
  99. {{ 'action.add_new_item'|trans({}, 'EasyAdminBundle') }}
  100. </button>
  101. {% endif %}
  102. {% endblock collection_widget %}
  103. {% block collection_entry_widget %}
  104. {% set is_complex = form_parent(form).vars.ea_crud_form.ea_field.customOptions.get('entryIsComplex') ?? false %}
  105. <div class="field-collection-item {{ is_complex ? 'field-collection-item-complex' }}">
  106. {% if form_parent(form).vars.allow_delete|default(false) %}
  107. <button type="button" class="btn btn-link field-collection-delete"
  108. title="{{ 'action.remove_item'|trans({}, 'EasyAdminBundle') }}">
  109. <i class="fas fa-times"></i>
  110. </button>
  111. {% endif %}
  112. {{ form_widget(form) }}
  113. </div>
  114. {% endblock collection_entry_widget %}
  115. {% block file_manager_image_row %}
  116. {{ form_widget(form) }}
  117. {% endblock file_manager_image_row %}
  118. {% block file_manager_legend_row %}
  119. {{ form_widget(form) }}
  120. {% endblock file_manager_legend_row %}
  121. {% block file_manager_position_row %}
  122. {{ form_widget(form) }}
  123. {% endblock file_manager_position_row %}
  124. {% block file_manager_widget %}
  125. {% if form.vars.ea_crud_form.ea_field is not null %}
  126. {% set managerDir = form.vars.ea_crud_form.ea_field.customOptions.get('managerDir') %}
  127. {% set type = form.vars.ea_crud_form.ea_field.customOptions.get('type') %}
  128. {% else %}
  129. {% set managerDir = form.vars.attr.type %}
  130. {% set type = form.vars.attr.type %}
  131. {% endif %}
  132. <div class="lc-filemanager row">
  133. {% if type == 'image' %}
  134. <div class="col-md-3 col-xs-12 form-group">
  135. <div class="lc-filemenager-preview card">
  136. <div class="no-image">
  137. <i class="fa fa-image"></i>
  138. </div>
  139. <img src="{{ form.path.vars.value }}" id="{{ form.path.vars.id }}_preview" alt=""
  140. class="card-img-top">
  141. </div>
  142. </div>
  143. {% else %}
  144. <div class="callout callout-success">
  145. <h5><i class="fa fa-file-alt"></i>
  146. <span id="{{ form.path.vars.id }}_preview_text">{{ form.path.vars.value }}</span>
  147. </h5>
  148. </div>
  149. {% endif %}
  150. <div class="col-12">
  151. <div class="input-group">
  152. <div class="input-group-prepend">
  153. {% if form.parent.vars['row_attr']['data-sortable'] is defined %}
  154. <button type="button" class="btn btn-success lc-btn-sortable" data-toggle="tooltip"
  155. title="Trier les images">
  156. <i class="fa fa-arrows-alt"></i>
  157. </button>
  158. {% endif %}
  159. <button type="button" class="btn btn-primary lc-filemanager-open" data-id="{{ form.path.vars.id }}"
  160. data-toggle="tooltip" title="Sélectionner un fichier"
  161. data-target="{{ path('file_manager', {module:1, conf: managerDir})|raw }}">
  162. <i class="fa fa-folder-open"></i>
  163. </button>
  164. </div>
  165. {{ form_widget(form.legend) }}
  166. <div class="input-group-append">
  167. <button type="button" class="btn btn-danger lc-filemanager-delete" data-toggle="tooltip"
  168. title="Supprimer l'image"
  169. data-id="{{ form.path.vars.id }}">
  170. <i class="fa fa-trash"></i>
  171. </button>
  172. </div>
  173. {{ form_rest(form) }}
  174. </div>
  175. </div>
  176. </div>
  177. {% endblock file_manager_widget %}
  178. {% block checkbox_radio_label -%}
  179. {#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
  180. {%- if widget is defined -%}
  181. {% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class or 'switch-custom' in parent_label_class) %}
  182. {% set is_custom = label_attr.class is defined and ('checkbox-custom' in label_attr.class or 'radio-custom' in label_attr.class or 'switch-custom' in label_attr.class) %}
  183. {%- if is_parent_custom or is_custom -%}
  184. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%}
  185. {%- else %}
  186. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%}
  187. {%- endif %}
  188. {%- if not compound -%}
  189. {% set label_attr = label_attr|merge({'for': id}) %}
  190. {%- endif -%}
  191. {%- if required -%}
  192. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
  193. {%- endif -%}
  194. {%- if parent_label_class is defined -%}
  195. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%}
  196. {%- endif -%}
  197. {%- if label is not same as(false) and label is empty -%}
  198. {%- if label_format is not empty -%}
  199. {%- set label = label_format|replace({
  200. '%name%': name,
  201. '%id%': id,
  202. }) -%}
  203. {%- else -%}
  204. {%- set label = name|humanize -%}
  205. {%- endif -%}
  206. {%- endif -%}
  207. <label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
  208. {{ widget|raw }}
  209. <span class="checkmark"></span>
  210. {# {% if translation_domain == 'lcshop' %}
  211. {{ name|lc_trad(easyadmin['entity']['name'], 'field') }}
  212. {% else %} #}
  213. {{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain))|raw -}}
  214. {# {% endif %} #}
  215. {{- form_errors(form) -}}
  216. </label>
  217. {%- endif -%}
  218. {%- endblock checkbox_radio_label %}
  219. {% block ea_crud_widget_panels %}
  220. {% embed '@LcSov/adminlte/embed/tabs/tabs.html.twig' %}
  221. {# items menu #}
  222. {% import '@LcSov/adminlte/macro/tabs.html.twig' as mtabs %}
  223. {% block menu_items %}
  224. {% for panel_name, panel_config in ea_crud_form.form_panels|filter(panel_config => not panel_config.form_tab or panel_config.form_tab == tab_name) %}
  225. {{ mtabs.menu_item(panel_name, loop.first, panel_config.label|lc_trans_admin_panel(ea.getEntity().getFqcn())) }}
  226. {% endfor %}
  227. {% endblock %}
  228. {# content #}
  229. {% block content %}
  230. {# panes #}
  231. {% for panel_name, panel_config in ea_crud_form.form_panels|filter(panel_config => not panel_config.form_tab or panel_config.form_tab == tab_name) %}
  232. {% embed '@LcSov/adminlte/embed/tabs/pane.html.twig' %}
  233. {% block class %}{{ loop.first ? 'active' }}{% endblock %}
  234. {% block id %}{{ panel_name }}{% endblock %}
  235. {% block content %}
  236. {% for field in form|filter(field => 'hidden' not in field.vars.block_prefixes and field.vars.ea_crud_form.form_panel == panel_name) %}
  237. {% if not field.vars.ea_crud_form.form_tab or field.vars.ea_crud_form.form_tab == tab_name %}
  238. {{ form_row(field) }}
  239. {% endif %}
  240. {% endfor %}
  241. {% endblock %}
  242. {% endembed %}
  243. {% else %}
  244. {% for field in form|filter(field => 'hidden' not in field.vars.block_prefixes and (not field.vars.ea_crud_form.form_tab or field.vars.ea_crud_form.form_tab == tab_name)) %}
  245. {{ form_row(field) }}
  246. {% endfor %}
  247. {% endfor %}
  248. {% endblock %}
  249. {% endembed %}
  250. {% endblock ea_crud_widget_panels %}