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 16KB

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