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.

323 lines
15KB

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