Validate image uploading in admin panel
Created 6 years ago by araminho

I have "file" and "files" fields, and I want that only images with certain dimensions are uploaded. Is there any way to handle that?

ryanthompson  —  6 years ago

You can add a custom validator for the dimensions part. Checkout how the upload field type does it internally: https://github.com/anomalylabs/upload-field_type/blob/1.1/src/UploadFieldType.php#L50

You would just override the field config on the builder to include your own validation like this for example: https://github.com/anomalylabs/users-module/blob/2.4/src/User/Form/UserFormFields.php#L33-L42

Note you have to define a custom rule - and also a validator for that custom rule.