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.

303 lines
14KB

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