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.

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