From 08346a21ec35f98441603389392062b6ba2e37e3 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 16 Oct 2023 20:26:33 +0200 Subject: [PATCH] - --- src/Dto/FormVarsDto.php | 4 ++ src/Resources/views/crud/form_theme.html.twig | 47 ++++++++++--------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/Dto/FormVarsDto.php b/src/Dto/FormVarsDto.php index fdf8e9cbff..c599dfee93 100644 --- a/src/Dto/FormVarsDto.php +++ b/src/Dto/FormVarsDto.php @@ -3,6 +3,10 @@ namespace EasyCorp\Bundle\EasyAdminBundle\Dto; /** + * It stores the variables related to EasyAdmin that are passed to all + * the form types templates via the `form.vars.ea_vars` variable. It's a similar + * concept to the variables passed by Symfony via the `form.vars` variable. + * * @author Javier Eguiluz */ final class FormVarsDto diff --git a/src/Resources/views/crud/form_theme.html.twig b/src/Resources/views/crud/form_theme.html.twig index ffacfcfd8f..6405f38d3e 100644 --- a/src/Resources/views/crud/form_theme.html.twig +++ b/src/Resources/views/crud/form_theme.html.twig @@ -75,31 +75,32 @@ {% set row_attr = row_attr|merge({ class: row_attr.class|default('') ~ ' form-group' }) %} + {% set field = form.vars.ea_vars.field %} -
+
{{- form_label(form) -}}
- {% set has_prepend_html = ea.field.prepend_html|default(null) is not null %} - {% set has_append_html = ea.field.append_html|default(null) is not null %} + {% set has_prepend_html = field.prepend_html|default(null) is not null %} + {% set has_append_html = field.append_html|default(null) is not null %} {% set has_input_groups = has_prepend_html or has_append_html %} {% if has_input_groups %}
{% endif %} {% if has_prepend_html %}
- {{ ea.field.prepend_html|raw }} + {{ field.prepend_html|raw }}
{% endif %} {{ form_widget(form) }} {% if has_append_html %} - {{ ea.field.append_html|raw }} + {{ field.append_html|raw }} {% endif %} {% if has_input_groups %}
{% endif %} - {% if ea.field.help ?? false %} - {{ ea.field.help|raw }} + {% if field.help ?? false %} + {{ field.help|raw }} {% elseif form.vars.help ?? false %} {{ form.vars.help|trans(form.vars.help_translation_parameters, form.vars.translation_domain)|raw }} {% endif %} @@ -110,7 +111,7 @@
{# if a field doesn't define its columns explicitly, insert a fill element to make the field take the entire row space #} - {% if form.vars.ea_crud_form.ea_field.columns|default(null) is null %} + {% if field.columns|default(null) is null %}
{% endif %} {% endblock form_row %} @@ -134,7 +135,7 @@ {% set row_attr = row_attr|merge({ 'data-ea-collection-field': 'true', - 'data-entry-is-complex': form.vars.ea_crud_form.ea_field and form.vars.ea_crud_form.ea_field.customOptions.get('entryIsComplex') ? 'true' : 'false', + 'data-entry-is-complex': form.vars.ea_vars.field and form.vars.ea_vars.field.customOptions.get('entryIsComplex') ? 'true' : 'false', 'data-allow-add': allow_add ? 'true' : 'false', 'data-allow-delete': allow_delete ? 'true' : 'false', 'data-num-items': form.children is empty ? 0 : max(form.children|keys), @@ -148,7 +149,7 @@ {# the "is iterable" check is needed because if an object implements __toString() and returns an empty string, "is empty" returns true even if it's not a collection #} {% set isEmptyCollection = value is null or (value is iterable and value is empty) %} - {% set is_array_field = 'EasyCorp\\Bundle\\EasyAdminBundle\\Field\\ArrayField' == form.vars.ea_crud_form.ea_field.fieldFqcn ?? false %} + {% set is_array_field = 'EasyCorp\\Bundle\\EasyAdminBundle\\Field\\ArrayField' == form.vars.ea_vars.field.fieldFqcn ?? false %}
{% if isEmptyCollection %} @@ -175,10 +176,10 @@ {% endblock collection_widget %} {% block collection_entry_row %} - {% set is_array_field = 'EasyCorp\\Bundle\\EasyAdminBundle\\Field\\ArrayField' == form_parent(form).vars.ea_crud_form.ea_field.fieldFqcn ?? false %} - {% set is_complex = form_parent(form).vars.ea_crud_form.ea_field.customOptions.get('entryIsComplex') ?? false %} + {% set is_array_field = 'EasyCorp\\Bundle\\EasyAdminBundle\\Field\\ArrayField' == form_parent(form).vars.ea_vars.field.fieldFqcn ?? false %} + {% set is_complex = form_parent(form).vars.ea_vars.field.customOptions.get('entryIsComplex') ?? false %} {% set allows_deleting_items = form_parent(form).vars.allow_delete|default(false) %} - {% set render_expanded = form_parent(form).vars.ea_crud_form.ea_field.customOptions.get('renderExpanded') ?? false %} + {% set render_expanded = form_parent(form).vars.ea_vars.field.customOptions.get('renderExpanded') ?? false %} {% set delete_item_button %}