Easyadminbundle: Trans error on "file_upload" field type

Created on 7 Jan 2020  路  2Comments  路  Source: EasyCorp/EasyAdminBundle

Describe the bug
Got an error when i use file_upload type field in entity form.

Argument 1 passed to Symfony\Bridge\Twig\Extension\TranslationExtension::trans() must be of the type string, null given, called in /var/www/ifp-agate/var/cache/dev/twig/8a/8a74945c05957e4d6e8025b4ee92abdddf9592cbe8fb84005b1cb413c31f9fec.php on line 1858

To Reproduce

  • Create a simple entity 'Student' with a string field 'photo'.
  • Add following easy_admin configuration :
       Student:
            class: App\Entity\Student
            form:
                fields:
                    - { property: 'photo', type: 'file_upload', type_options: { required: false, upload_dir: 'public/uploads/student/photo/' } }
  • Access o the form, you've got the error

image

(OPTIONAL) Additional context

image

* Try to fix ? *
The bug seems to be in src/Resources/views/form/bootstrap_4.html.twig at line 636
placeholder and title are initialized to null. But on an empty field, it seems to be a problem.

I have overrided this template with my own custom form theme that extend the first one and i have replaced :

{{ form_widget(form.file, { attr: form.file.vars.attr|merge({ placeholder: placeholder, title: title, 'data-files-label': filesLabel }) }) }}

by

            {% set custom_attrs = { 'data-files-label': filesLabel } %}
            {% if placeholder is not null and title is not null %}
                {% set custom_attrs =  custom_attrs|merge({ placeholder: placeholder, title: title}) %}
            {% endif %}

            {{ form_widget(form.file, { attr: form.file.vars.attr|merge(custom_attrs) }) }}
bug confirmed

Most helpful comment

Thanks for reporting this. It was solved by @mitalcoi in #3017 and it will be part of the next stable version to be released soon.

All 2 comments

Same issue here, can confirm that overriding the template fixes the problem.

Thanks for reporting this. It was solved by @mitalcoi in #3017 and it will be part of the next stable version to be released soon.

Was this page helpful?
0 / 5 - 0 ratings