{% use "core/form/bootstrap_base_layout.html.twig" %} {# Widgets #} {% block money_widget -%} {%- set prepend = not (money_pattern starts with '{{') -%} {%- set append = not (money_pattern ends with '}}') -%} {%- if prepend or append -%}
{%- if prepend -%}
{{ money_pattern|form_encode_currency }}
{%- endif -%} {{- block('form_widget_simple') -}} {%- if append -%}
{{ money_pattern|form_encode_currency }}
{%- endif -%}
{%- else -%} {{- block('form_widget_simple') -}} {%- endif -%} {%- endblock money_widget %} {% block datetime_widget -%} {%- if widget != 'single_text' and not valid -%} {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) -%} {% set valid = true %} {%- endif -%} {{- parent() -}} {%- endblock datetime_widget %} {% block date_widget -%} {%- if widget != 'single_text' and not valid -%} {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) -%} {% set valid = true %} {%- endif -%} {{- parent() -}} {%- endblock date_widget %} {% block time_widget -%} {%- if widget != 'single_text' and not valid -%} {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) -%} {% set valid = true %} {%- endif -%} {{- parent() -}} {%- endblock time_widget %} {% block dateinterval_widget -%} {%- if widget != 'single_text' and not valid -%} {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) -%} {% set valid = true %} {%- endif -%} {%- if widget == 'single_text' -%} {{- block('form_widget_simple') -}} {%- else -%} {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
{%- if with_years -%}
{{ form_label(form.years) }} {{ form_widget(form.years) }}
{%- endif -%} {%- if with_months -%}
{{ form_label(form.months) }} {{ form_widget(form.months) }}
{%- endif -%} {%- if with_weeks -%}
{{ form_label(form.weeks) }} {{ form_widget(form.weeks) }}
{%- endif -%} {%- if with_days -%}
{{ form_label(form.days) }} {{ form_widget(form.days) }}
{%- endif -%} {%- if with_hours -%}
{{ form_label(form.hours) }} {{ form_widget(form.hours) }}
{%- endif -%} {%- if with_minutes -%}
{{ form_label(form.minutes) }} {{ form_widget(form.minutes) }}
{%- endif -%} {%- if with_seconds -%}
{{ form_label(form.seconds) }} {{ form_widget(form.seconds) }}
{%- endif -%} {%- if with_invert %}{{ form_widget(form.invert) }}{% endif -%}
{%- endif -%} {%- endblock dateinterval_widget %} {% block percent_widget -%} {%- if symbol -%}
{{- block('form_widget_simple') -}}
{{ symbol|default('%') }}
{%- else -%} {{- block('form_widget_simple') -}} {%- endif -%} {%- endblock percent_widget %} {% block file_widget -%} {% set isDropzone = attr.class is defined and 'dropzone' in attr.class %} {% set isDropify = attr.class is defined and 'dropify' in attr.class %} {%- if isDropzone -%} {{- block('form_widget_simple') -}} {%- elseif isDropify -%} {% set isMedia = false %} {% set filename = form.parent.parent.vars.data.media.filename is defined and form.parent.parent.vars.data.media.filename ? app.request.getSchemeAndHttpHost() ~ '/uploads/' ~ website().uploadDirname ~ '/' ~ form.parent.parent.vars.data.media.filename : "" %} {%- if not filename -%} {% set isMedia = true %} {% set filename = form.parent.vars.data.filename is defined and form.parent.vars.data.filename ? app.request.getSchemeAndHttpHost() ~ '/uploads/' ~ website().uploadDirname ~ '/' ~ form.parent.vars.data.filename : "" %} {%- endif -%} {%- if filename -%} {% set mediaExist = form.parent.parent.vars.data is defined and form.parent.parent.vars.data.media is defined %} {%- if mediaExist and not isMedia -%} {%- set attr = attr|merge({ ("data-media-relation"): form.parent.parent.vars.data.id|trim }) -%} {%- elseif isMedia -%} {%- set attr = attr|merge({ ("data-media"): form.parent.vars.data.id|trim }) -%} {%- if form.parent.vars.data.screen is defined -%} {%- set attr = attr|merge({ ("data-screen"): form.parent.vars.data.screen|trim }) -%} {%- endif -%} {%- endif -%} {%- set attr = attr|merge({ ("data-default-file"): filename|trim }) -%} {%- set attr = attr|merge({ ("data-height"): 250|trim }) -%} {%- set attr = attr|merge({ ("data-errors-position"): "outside"|trim }) -%} {%- endif -%} {{- block('form_widget_simple') -}} {%- else -%} {%- if attr['data-btn'] is defined and 'btn' in attr['data-btn'] -%} {% set placeholder = attr.placeholder is defined and attr.placeholder ? attr.placeholder : null %} {% if not placeholder and attr.multiple is defined %} {% set placeholder = "Ajouter des fichiers"|trans %} {% elseif not placeholder %} {% set placeholder = "Ajouter un fichier"|trans %} {% endif %} {% set icon = attr['data-icon'] is defined and attr['data-icon'] ? attr['data-icon'] : null %} {%- else -%} <{{ element|default('div') }} class="custom-file"> {%- set type = type|default('file') -%} {{- block('form_widget_simple') -}} {%- set label_attr = label_attr|merge({ class: (label_attr.class|default('') ~ ' custom-file-label')|trim }) -%} {%- endif -%} {%- endif -%} {% endblock %} {% block form_widget_simple -%} {% if type is not defined or type != 'hidden' %} {%- set attr = attr|merge({class: (attr.class|default('') ~ (type|default('') == 'file' ? ' custom-file-input' : ' form-control'))|trim}) -%} {% endif %} {%- if type is defined and (type == 'range' or type == 'color') %} {# Attribute "required" is not supported #} {%- set required = false -%} {% endif %} {{- parent() -}} {% if attr.code is defined and attr.code %} {{ "Générer le code"|trans([], 'admin')|raw }} {% endif %} {% if attr.group is defined and 'password-generator' in attr.group %} {{ "Générer un mot de passe"|trans([], 'admin')|raw }} {% endif %} {% if bytes is defined and bytes %} {{ "Générer"|trans([], 'admin')|raw }} {% endif %} {%- endblock form_widget_simple %} {%- block widget_attributes -%} {%- if not valid %} {% set attr = attr|merge({class: (attr.class|default('') ~ ' is-invalid')|trim}) %} {% endif -%} {{ parent() }} {%- endblock widget_attributes -%} {% block button_widget -%} {%- set attr = attr|merge({class: (attr.class|default('btn-secondary') ~ ' btn')|trim}) -%} {{- parent() -}} {%- endblock button_widget %} {% block submit_widget -%} {%- set attr = attr|merge({class: (attr.class|default('btn-primary'))|trim}) -%} {{- parent() -}} {%- endblock submit_widget %} {% block checkbox_widget -%} {%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%} {%- if 'custom-control-label' in parent_label_class or form.parent.vars.attr.class is defined and form.parent.vars.attr.class == 'switch' -%} {%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
{{- form_label(form, null, { widget: parent() }) -}}
{%- elseif 'checkbox-custom' in parent_label_class -%} {%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
{{- form_label(form, null, { widget: parent() }) -}}
{%- else -%} {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
{{- form_label(form, null, { widget: parent() }) -}}
{%- endif -%} {%- endblock checkbox_widget %} {% block radio_widget -%} {%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%} {%- if 'radio-custom' in parent_label_class -%} {%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
{{- form_label(form, null, { widget: parent() }) -}}
{%- else -%} {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
{{- form_label(form, null, { widget: parent() }) -}}
{%- endif -%} {%- endblock radio_widget %} {% block choice_widget_expanded -%}
{%- for child in form %} {{- form_widget(child, { parent_label_class: label_attr.class|default(''), translation_domain: choice_translation_domain, valid: valid, }) -}} {% endfor -%}
{%- endblock choice_widget_expanded %} {# Labels #} {% block form_label -%} {% if label is not same as(false) and label -%} {%- if compound is defined and compound -%} {%- set element = 'legend' -%} {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-label')|trim}) -%} {%- else -%} {%- set label_attr = label_attr|merge({for: id}) -%} {%- endif -%} {% if required -%} {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %} {%- endif -%} {% if label is empty -%} {%- if label_format is not empty -%} {% set label = label_format|replace({ '%name%': name, '%id%': id, }) %} {%- else -%} {% set label = name|humanize %} {%- endif -%} {%- endif -%} <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}> {{ translation_domain is same as(false) ? label : label|trans(label_translation_parameters, translation_domain)|raw }} {% if required is defined and required %} * {% endif %} {% if name is defined and name == "adminName" %} {{ "(Visible uniquement dans le back office)"|trans([], 'admin')|raw }} {% endif %} {% block form_label_errors %} {{- form_errors(form) -}} {% endblock form_label_errors %} {%- else -%} {%- if errors|length > 0 -%}
{{- form_errors(form) -}}
{%- endif -%} {%- endif -%} {%- endblock form_label %} {% block checkbox_radio_label -%} {#- Do not display the label if widget is not defined in order to prevent double label rendering -#} {%- if widget is defined -%} {% set is_parent_custom = parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class) %} {% set is_custom = label_attr.class is defined and ('checkbox-custom' in label_attr.class or 'radio-custom' in label_attr.class) %} {%- if is_parent_custom or is_custom -%} {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%} {%- else %} {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%} {%- endif %} {%- if not compound -%} {% set label_attr = label_attr|merge({'for': id}) %} {%- endif -%} {%- if required -%} {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%} {%- endif -%} {%- if parent_label_class is defined -%} {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%} {%- endif -%} {%- if label is not same as(false) and label is empty -%} {%- if label_format is not empty -%} {%- set label = label_format|replace({ '%name%': name, '%id%': id, }) -%} {%- else -%} {%- set label = name|humanize -%} {%- endif -%} {%- endif -%} {{ widget|raw }} {{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)|raw) -}} {{- form_errors(form) -}} {%- endif -%} {%- endblock checkbox_radio_label %} {# Rows #} {% block form_row -%} {% set formGroup = attr.group is defined ? attr.group : 'col-12' %} {% set counterExist = counter is defined %} {% set hasColorPicker = attr.class is defined and 'colorpicker' in attr.class %} {% set invalid = (not compound or force_error|default(false)) and not valid %} {%- if compound is defined and compound -%} {%- set element = 'fieldset' -%} {%- endif -%} {%- if 'datetime' in block_prefixes or 'date' in block_prefixes -%} {%- set element = 'div' -%} {%- endif -%} {%- set widget_attr = {} -%} {%- if help is not empty -%} {%- set widget_attr = {attr: {'aria-describedby': id ~ "_help"}} -%} {%- endif -%} {%- if element|default('div') != 'fieldset' -%} <{{ element|default('div') }} class="form-group {% if formGroup %} {{ formGroup }}{% endif %} {% if counterExist %} counter-form-group{% endif %} {% if invalid %} is-invalid{% endif %} {% if hasColorPicker %} colorpicker-group{% endif %}"> {%- endif -%} {{- form_label(form) -}} {{- form_widget(form, widget_attr) -}} {% if counterExist %} {{ value|striptags|length }} / {{ counter }} {{ "caractères recommandés"|trans([], 'admin')|raw }} {% endif %} {{- form_help(form) -}} {%- if element|default('div') != 'fieldset' -%} {%- endif -%} {%- endblock form_row %} {# Errors #} {% block form_errors -%} {%- if errors|length > 0 -%} {%- for error in errors -%} {{ 'Error'|trans({}, 'validators')|raw }} {{ error.message }} {%- endfor -%} {%- endif %} {%- endblock form_errors %} {# Help #} {% block form_help -%} {%- if help is not empty -%} {%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' form-text text-info')|trim}) -%} {%- if translation_domain is same as(false) -%} {%- if help_html is same as(false) -%} {{- help|raw -}} {%- else -%} {{- help|raw -}} {%- endif -%} {%- else -%} {%- if help_html is same as(false) -%} {{- help|trans(help_translation_parameters, translation_domain)|raw -}} {%- else -%} {{- help|trans(help_translation_parameters, translation_domain)|raw -}} {%- endif -%} {%- endif -%} {%- endif -%} {%- endblock form_help %}