Easyadminbundle: FileType Not Work With Config "yield ImageField::new('picture')"

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

Bug EA 3

For editing images in my Controller class MediaProfilCrudController extends AbstractCrudController

public function configureFields(string $pageName): iterable
{
yield IntegerField::new('id', 'ID')->onlyOnIndex();
yield ImageField::new('picture')
->setBasePath('assets/img/picture/');
}

I get this error :

The form's view data is expected to be a "Symfony\Component\HttpFoundation\File\File", but it is a "string". You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms "string" to an instance of "Symfony\Component\HttpFoundation\File\File".

bug

Most helpful comment

I used it this way and its working

$avatar = ImageField::new('avatar')->setBasePath('uploads/images/users')->setLabel('Photo');
$avatarFile = ImageField::new('avatarFile')->setFormType(VichImageType::class);

 if (Crud::PAGE_INDEX === $pageName) {
            return [ $avatar];
     } elseif (Crud::PAGE_EDIT=== $pageName) {
return [$avatarFile];

All 7 comments

I used it this way and its working

$avatar = ImageField::new('avatar')->setBasePath('uploads/images/users')->setLabel('Photo');
$avatarFile = ImageField::new('avatarFile')->setFormType(VichImageType::class);

 if (Crud::PAGE_INDEX === $pageName) {
            return [ $avatar];
     } elseif (Crud::PAGE_EDIT=== $pageName) {
return [$avatarFile];

Thanks @Merazsohel i try
yield ImageField::new('pictureFile')->setFormType(VichImageType::class)->setLabel('Picture');
its working

I think this issue can be closed now.

@seb-jean sure

Can you close this issue?

@seb-jean No. I can't close this issue because of i have no permission. This issue opened by others.

@javiereguiluz can you please close this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

javiereguiluz picture javiereguiluz  路  4Comments

cve picture cve  路  4Comments

SirMishaa picture SirMishaa  路  3Comments

ziobudda picture ziobudda  路  4Comments

haithem-rihane picture haithem-rihane  路  4Comments