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.

345 lines
16KB

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