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