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.

354 lines
16KB

  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 not entityNameOrObject and form.parent.vars.errors.form.config.dataClass is defined %}
  104. {% set entityNameOrObject = form.parent.vars.errors.form.config.dataClass %}
  105. {% endif %}
  106. {% if translation_domain == null %}
  107. {% set translation_domain = 'admin' %}
  108. {% endif %}
  109. <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}
  110. >{{ (label is not empty and '.' in label) ? label|trans({}, translation_domain) : name|sov_trans_admin_field(entityNameOrObject) }}
  111. </{{ element|default('label') }}>
  112. {%- endif -%}
  113. {%- endblock form_label %}
  114. {% block gallery_manager_row %}
  115. {{ block('collection_row') }}
  116. {% endblock gallery_manager_row %}
  117. {% block gallery_manager_widget %}
  118. {{ block('collection_widget') }}
  119. {% endblock gallery_manager_widget %}
  120. {% block collection_row %}
  121. {% if prototype is defined and not prototype.rendered %}
  122. {% set row_attr = row_attr|merge({ 'data-prototype': form_row(prototype) }) %}
  123. {% endif %}
  124. {% set row_attr = row_attr|merge({
  125. 'data-entry-is-complex': form.vars.ea_crud_form.ea_field and form.vars.ea_crud_form.ea_field.customOptions.get('entryIsComplex') ? 'true' : 'false',
  126. 'data-allow-add': allow_add ? 'true' : 'false',
  127. 'data-allow-delete': allow_delete ? 'true' : 'false',
  128. 'data-num-items': form.children|length,
  129. 'data-form-type-name-placeholder': prototype is defined ? prototype.vars.name : '',
  130. }) %}
  131. {{ block('form_row') }}
  132. {% endblock collection_row %}
  133. {% block collection_widget %}
  134. {{ block('form_widget') }}
  135. {% if allow_add|default(false) %}
  136. <button type="button" class="btn btn-link field-collection-add">
  137. <i class="fa fa-plus pr-1"></i>
  138. {{ 'action.add_new_item'|trans({}, 'EasyAdminBundle') }}
  139. </button>
  140. {% endif %}
  141. {% endblock collection_widget %}
  142. {% block collection_entry_widget %}
  143. {% set is_complex = form_parent(form).vars.ea_crud_form.ea_field.customOptions.get('entryIsComplex') ?? false %}
  144. <div class="field-collection-item {{ is_complex ? 'field-collection-item-complex' }}">
  145. {% if form_parent(form).vars.allow_delete|default(false) %}
  146. <button type="button" class="btn btn-link field-collection-delete"
  147. title="{{ 'action.remove_item'|trans({}, 'EasyAdminBundle') }}">
  148. <i class="fas fa-times"></i>
  149. </button>
  150. {% endif %}
  151. {{ form_widget(form) }}
  152. </div>
  153. {% endblock collection_entry_widget %}
  154. {% block file_manager_image_row %}
  155. {{ form_widget(form) }}
  156. {% endblock file_manager_image_row %}
  157. {% block file_manager_legend_row %}
  158. {{ form_widget(form) }}
  159. {% endblock file_manager_legend_row %}
  160. {% block file_manager_position_row %}
  161. {{ form_widget(form) }}
  162. {% endblock file_manager_position_row %}
  163. {% block file_manager_widget %}
  164. {% if form.vars.ea_crud_form.ea_field is not null %}
  165. {% set managerDir = form.vars.ea_crud_form.ea_field.customOptions.get('managerDir') %}
  166. {% set type = form.vars.ea_crud_form.ea_field.customOptions.get('type') %}
  167. {% else %}
  168. {% if form.vars.attr.type is defined %}
  169. {% set managerDir = form.vars.attr.type %}
  170. {% set type = form.vars.attr.type %}
  171. {% endif %}
  172. {% endif %}
  173. {% if type is defined %}
  174. <div class="lc-filemanager row">
  175. {% if type == 'image' %}
  176. <div class="col-md-3 col-xs-12 form-group">
  177. <div class="lc-filemenager-preview card">
  178. <div class="no-image">
  179. <i class="fa fa-image"></i>
  180. </div>
  181. <img src="{{ form.path.vars.value }}" id="{{ form.path.vars.id }}_preview" alt=""
  182. class="card-img-top">
  183. </div>
  184. </div>
  185. {% else %}
  186. <div class="callout callout-success">
  187. <h5><i class="fa fa-file-alt"></i>
  188. <span id="{{ form.path.vars.id }}_preview_text">{{ form.path.vars.value }}</span>
  189. </h5>
  190. </div>
  191. {% endif %}
  192. <div class="col-12">
  193. {# {{ dump(form.vars) }} #}
  194. {# {{ dump(form.vars.ea_crud_form.ea_field) }} #}
  195. <div class="input-group">
  196. <div class="input-group-prepend">
  197. {% if form.parent.vars['row_attr']['data-sortable'] is defined %}
  198. <button type="button" class="btn btn-success lc-btn-sortable" data-toggle="tooltip"
  199. title="Trier les images">
  200. <i class="fa fa-arrows-alt"></i>
  201. </button>
  202. {% endif %}
  203. <button type="button" class="btn btn-primary lc-filemanager-open"
  204. data-id="{{ form.path.vars.id }}"
  205. data-toggle="tooltip" title="Sélectionner un fichier"
  206. data-target="{{ path('file_manager', {module:1, conf: managerDir})|raw }}">
  207. <i class="fa fa-folder-open"></i>
  208. </button>
  209. </div>
  210. {{ form_widget(form.legend) }}
  211. <div class="input-group-append">
  212. <button type="button" class="btn btn-danger lc-filemanager-delete" data-toggle="tooltip"
  213. title="Supprimer l'image"
  214. data-id="{{ form.path.vars.id }}">
  215. <i class="fa fa-trash"></i>
  216. </button>
  217. </div>
  218. {{ form_rest(form) }}
  219. </div>
  220. </div>
  221. </div>
  222. {% endif %}
  223. {% endblock file_manager_widget %}
  224. {% block checkbox_radio_label -%}
  225. {#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
  226. {%- if widget is defined -%}
  227. {% 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) %}
  228. {% 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) %}
  229. {%- if is_parent_custom or is_custom -%}
  230. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%}
  231. {%- else %}
  232. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%}
  233. {%- endif %}
  234. {%- if not compound -%}
  235. {% set label_attr = label_attr|merge({'for': id}) %}
  236. {%- endif -%}
  237. {%- if required -%}
  238. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
  239. {%- endif -%}
  240. {%- if parent_label_class is defined -%}
  241. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%}
  242. {%- endif -%}
  243. {%- if label is not same as(false) and label is empty -%}
  244. {%- if label_format is not empty -%}
  245. {%- set label = label_format|replace({
  246. '%name%': name,
  247. '%id%': id,
  248. }) -%}
  249. {%- else -%}
  250. {%- set label = name|humanize -%}
  251. {%- endif -%}
  252. {%- endif -%}
  253. {% if attr.disabled is defined and attr.disabled %}
  254. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' disabled')|trim}) -%}
  255. {% endif %}
  256. <label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
  257. {{ widget|raw }}
  258. <span class="checkmark"></span>
  259. {# {{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain))|raw -}} #}
  260. {% set entityNameOrObject = form.parent.vars.data %}
  261. {% if not entityNameOrObject and form.parent.vars.errors.form.config.dataClass is defined %}
  262. {% set entityNameOrObject = form.parent.vars.errors.form.config.dataClass %}
  263. {% endif %}
  264. <!-- lorsque que le name est un entier "case radio"-->
  265. {% if name matches '/^\\d+$/' %}
  266. {{- label|trans({}, 'admin') -}}
  267. {% else %}
  268. {{- (label is not empty and '.' in label) ? label|trans({}, 'admin') : name|sov_trans_admin_field(entityNameOrObject) -}}
  269. {% endif %}
  270. {{- form_errors(form) -}}
  271. </label>
  272. {%- endif -%}
  273. {%- endblock checkbox_radio_label %}
  274. {% block ea_crud_widget_panels %}
  275. {% embed '@LcSov/adminlte/embed/tabs/tabs.html.twig' %}
  276. {# items menu #}
  277. {% import '@LcSov/adminlte/macro/tabs.html.twig' as mtabs %}
  278. {% block menu_items %}
  279. {% 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) %}
  280. {{ mtabs.menu_item(panel_name, loop.first, panel_config.label|sov_trans_admin_panel(ea.getEntity().getFqcn())) }}
  281. {% endfor %}
  282. {% endblock %}
  283. {# content #}
  284. {% block content %}
  285. {# panes #}
  286. {% 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) %}
  287. {% embed '@LcSov/adminlte/embed/tabs/pane.html.twig' %}
  288. {% block class %}{{ loop.first ? 'active' }}{% endblock %}
  289. {% block id %}{{ panel_name }}{% endblock %}
  290. {% block content %}
  291. {% for field in form|filter(field => 'hidden' not in field.vars.block_prefixes and field.vars.ea_crud_form.form_panel == panel_name) %}
  292. {% if not field.vars.ea_crud_form.form_tab or field.vars.ea_crud_form.form_tab == tab_name %}
  293. {{ form_row(field) }}
  294. {% endif %}
  295. {% endfor %}
  296. {% endblock %}
  297. {% endembed %}
  298. {% else %}
  299. {% 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)) %}
  300. {{ form_row(field) }}
  301. {% endfor %}
  302. {% endfor %}
  303. {% endblock %}
  304. {% endembed %}
  305. {% endblock ea_crud_widget_panels %}
  306. {% block ckeditor_widget %}
  307. <textarea class="lc-ckeditor" {{ block('widget_attributes') }}>{{ value }}</textarea>
  308. {% endblock %}