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.

339 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. {% set managerDir = form.vars.ea_crud_form.ea_field.customOptions.get('managerDir') %}
  126. {% set type = form.vars.ea_crud_form.ea_field.customOptions.get('type') %}
  127. <div class="lc-filemanager row">
  128. {% if type == 'image' %}
  129. <div class="col-md-3 col-xs-12 form-group">
  130. <div class="lc-filemenager-preview card">
  131. <div class="no-image">
  132. <i class="fa fa-image"></i>
  133. </div>
  134. <img src="{{ form.path.vars.value }}" id="{{ form.path.vars.id }}_preview" alt="" class="card-img-top">
  135. </div>
  136. </div>
  137. {% else %}
  138. <div class="callout callout-success">
  139. <h5><i class="fa fa-file-alt"></i>
  140. <span id="{{ form.path.vars.id }}_preview_text">{{ form.path.vars.value }}</span>
  141. </h5>
  142. </div>
  143. {% endif %}
  144. <div class="col-12">
  145. <div class="input-group">
  146. <div class="input-group-prepend">
  147. {% if form.parent.vars['row_attr']['data-sortable'] is defined %}
  148. <button type="button" class="btn btn-success lc-btn-sortable" data-toggle="tooltip"
  149. title="Trier les images">
  150. <i class="fa fa-arrows-alt"></i>
  151. </button>
  152. {% endif %}
  153. <button type="button" class="btn btn-primary lc-filemanager-open" data-id="{{ form.path.vars.id }}"
  154. data-toggle="tooltip" title="Sélectionner un fichier"
  155. data-target="{{ path('file_manager', {module:1, conf: managerDir})|raw }}">
  156. <i class="fa fa-folder-open"></i>
  157. </button>
  158. </div>
  159. {{ form_widget(form.legend) }}
  160. <div class="input-group-append">
  161. <button type="button" class="btn btn-danger lc-filemanager-delete" data-toggle="tooltip"
  162. title="Supprimer l'image"
  163. data-id="{{ form.path.vars.id }}">
  164. <i class="fa fa-trash"></i>
  165. </button>
  166. </div>
  167. {{ form_rest(form) }}
  168. </div>
  169. </div>
  170. </div>
  171. {% endblock file_manager_widget %}
  172. {% block checkbox_radio_label -%}
  173. {#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
  174. {%- if widget is defined -%}
  175. {% 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) %}
  176. {% 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) %}
  177. {%- if is_parent_custom or is_custom -%}
  178. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%}
  179. {%- else %}
  180. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%}
  181. {%- endif %}
  182. {%- if not compound -%}
  183. {% set label_attr = label_attr|merge({'for': id}) %}
  184. {%- endif -%}
  185. {%- if required -%}
  186. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
  187. {%- endif -%}
  188. {%- if parent_label_class is defined -%}
  189. {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%}
  190. {%- endif -%}
  191. {%- if label is not same as(false) and label is empty -%}
  192. {%- if label_format is not empty -%}
  193. {%- set label = label_format|replace({
  194. '%name%': name,
  195. '%id%': id,
  196. }) -%}
  197. {%- else -%}
  198. {%- set label = name|humanize -%}
  199. {%- endif -%}
  200. {%- endif -%}
  201. <label{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
  202. {{ widget|raw }}
  203. <span class="checkmark"></span>
  204. {# {% if translation_domain == 'lcshop' %}
  205. {{ name|lc_trad(easyadmin['entity']['name'], 'field') }}
  206. {% else %} #}
  207. {{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain))|raw -}}
  208. {# {% endif %} #}
  209. {{- form_errors(form) -}}
  210. </label>
  211. {%- endif -%}
  212. {%- endblock checkbox_radio_label %}
  213. {% block form_start %}
  214. {{ parent() }}
  215. {% if ea_crud_form.form_panels is defined %}
  216. <div class="card card-outline">
  217. <div class="card-header p-0 border-bottom-0">
  218. <ul id="nav-params" class="nav nav-pills" role="navigation">
  219. {% 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) %}
  220. {% set panel_has_header = panel_config.label|default(false) or panel_config.icon|default(false) %}
  221. <li class="nav-item">
  222. <a href="#panel-{{ panel_name }} " class="nav-link {{ panel_name == 1 ? 'active' }}"
  223. data-toggle="tab" role="tab"
  224. aria-controls="panel-{{ panel_name }}">
  225. {{ panel_config.label|lc_trans_admin_panel(ea.getEntity().getFqcn()) }}
  226. <i class="fa fa-exclamation-circle invalid-form"></i>
  227. </a>
  228. </li>
  229. {% endfor %}
  230. </ul>
  231. </div>
  232. </div>
  233. {% endif %}
  234. {% endblock form_start %}
  235. {% block ea_crud_widget_panels %}
  236. <div class="tab-content">
  237. {% 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) %}
  238. {% set panel_has_header = panel_config.label|default(false) or panel_config.icon|default(false) %}
  239. {% set collapsible = panel_config.collapsible %}
  240. {% set collapsed = panel_config.collapsed %}
  241. <div class="tab-pane {{ panel_name == 1 ? 'active' }}" id="panel-{{ panel_name }}"
  242. aria-labelledby="{{ panel_name }}-tab">
  243. {% if panel_config.template is defined and panel_config.template is not null %}
  244. {% include panel_config.template %}
  245. {% else %}
  246. <div class="card {{ panel_config.css_class ?? '' }}">
  247. <div class="card-status-top bg-primary"></div>
  248. <div class="card-header ">
  249. {% if panel_has_header %}
  250. {# <div class="content-panel-header {{ collapsible ? 'collapsible' }} {{ panel_config.help|default(false) is not empty ? 'with-help' }}"> #}
  251. {% if collapsible %}
  252. <a href="#content-{{ panel_name }}" data-toggle="collapse" class="content-panel-collapse {{ collapsed ? 'collapsed' }}" aria-expanded="{{ collapsed ? 'false' : 'true' }}" aria-controls="content-{{ panel_name }}">
  253. <i class="fas fw fa-chevron-right collapse-icon"></i>
  254. {% endif %}
  255. {% if panel_config.icon|default(false) %}
  256. <i class="{{ panel_config.icon }}"></i>
  257. {% endif %}
  258. {{ panel_config.label|lc_trans_admin_panel(ea.getEntity().getFqcn()) }}
  259. {% if collapsible %}
  260. </a>
  261. {% endif %}
  262. {% if panel_config.help|default(false) %}
  263. <div class="content-panel-header-help">{{ panel_config.help|raw }}</div>
  264. {% endif %}
  265. {% endif %}
  266. </div>
  267. <div class="card-body {{ collapsible ? 'collapse' }} {{ not collapsed ? 'show' }}">
  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. </div>
  274. </div>
  275. {% endif %}
  276. </div>
  277. {% else %}
  278. <div class="card">
  279. <div class="card-status-top bg-primary"></div>
  280. <div class="card-header "></div>
  281. <div class="card-body">
  282. {% 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)) %}
  283. {{ form_row(field) }}
  284. {% endfor %}
  285. </div>
  286. </div>
  287. {% endfor %}
  288. </div>
  289. {% endblock ea_crud_widget_panels %}