EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.04k stars 1.02k forks source link

Collection of custom type not saving files in database #4944

Open Dumorya opened 2 years ago

Dumorya commented 2 years ago

Describe the bug If have a collection of a custom type (PhotoType, which is basically just a FileType with a Image constraint), like this:

CollectionField::new('photos') ->setFormTypeOptions([ 'entry_type' => PhotoType::class, ])

It displays well the PhotoType with a "add button" which allows us to create a new one, but if I choose a file and save the form, the number of Photos are well saved, but the arrays are empty. No filename is saved. Like this:

a:2:{i:1;a:0:{}i:2;a:0:{}}

To Reproduce EasyAdmin version used: 3.5.17

Create a PhotoType (with the one I provided), add it in a Crud with the code above, choose file and check what is saved in database.

(OPTIONAL) Additional context Here is my PhotoType:

`class PhotoType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('photo', FileType::class, [
                'mapped' => false,
                'required' => false,
                'constraints' => [
                    new Image([
                        'maxSize' => '10M',
                        'mimeTypesMessage' => 'Please upload a valid image document',
                    ])
                ],
                'label' => 'Choose a file'
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
        ]);
    }
}`
Dumorya commented 2 years ago

@javiereguiluz would you have an idea?

Dumorya commented 2 years ago

Actually I found out that a simple FileField has the same behaviour, the issue has nothing to do with the CollectionField. The FileField doesn't save the data.