Currently, it is not possible to properly validate images uploaded with the ImageField using Symfony constraints.
This is because the constraints option is applied to both the parent field (returning a string) and the underlying FileType field (returning an UploadedFile) resulting in unexpected validation errors.
This PR adds a new setFileConstraints method to the ImageField to apply constraints to the FileType field only.
By default, I also applied the Image constraint on the ImageField.
Usage example:
use Symfony\Component\Validator\Constraints\Image;
// Validate that file is an image by default
ImageField::new('logo', 'Logo'),
// Set custom validation constraints
ImageField::new('logo', 'Logo')->setFileConstraints(new Image(maxSize: '100k')),
Fixes https://github.com/EasyCorp/EasyAdminBundle/issues/5227 and https://github.com/EasyCorp/EasyAdminBundle/issues/4088
Currently, it is not possible to properly validate images uploaded with the
ImageField
using Symfony constraints. This is because theconstraints
option is applied to both the parent field (returning astring
) and the underlyingFileType
field (returning anUploadedFile
) resulting in unexpected validation errors.This PR adds a new
setFileConstraints
method to theImageField
to apply constraints to theFileType
field only. By default, I also applied theImage
constraint on theImageField
.Usage example: