-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a form API element for image
that includes image type and size validators natively.
#5946
Comments
Should be there just an image form element, or also an image_managed field? |
The reason for having an image form element is that the accepted image types are the ones recognized by the enabled image toolkit. One of the validation handlers needs to ask to the image toolkit if the uploaded image is one the toolkit can handle. We do not have a sound toolkit to which pass a sound file; that is the reason for which we do not need a form element that is different from the file form element, for sounds. |
Right @kiamlaluno 👍🏼 Where I was getting at is that if we had either I understand what you are saying with re to images, and the fact that they need special handling for their previews by whatever toolkit is available makes it more complex. But we can always allow the image to be uploaded as a "plain" file (link to download the file instead of trying to render it or its thumbnail), even if the toolkit doesn't support the specific type. Right? And finally, I am not disagreeing with the proposal to add special handling for images in the FAPI - I'm considering different approaches than the one proposed here. So the suggestion is to basically add support for something like this: $form['image'] = array(
'#title' => t('Upload an image'),
'#type' => 'image',
...
); ...and what I am saying is that we could do this instead: $form['image'] = array(
'#title' => t('Upload an image'),
'#type' => 'file',
'#file_types' => array('image'),
...
); Why? Because if we add a new FAPI element for images, then we may need to add for other types in the future. If we add a way to be able to specify the type of the file we intent to handle (via a property in the existing I hope this all makes sense, and please do note that this is just an idea - I have't considered everything. |
If I upload an image for my user account, I expect it to be shown, not to get a link to download it, which is not helpful, since I have the image already in my computer and users visiting my user profile do not want to download a file, but see my "virtual face." I understand that we are exposing an idea, but we should not worry about audio files, which are not used from Backdrop core for any purpose, differently from images which are used from some core forms and shown in some places. The actual issue is that users see contradictory error messages when they upload images. If the toolkit supports the image type, they could get an error about the used file extension; if they select a file with an accepted file extension (for example .doc), they could get an error about the image type (which is possibly not an image type, if the file has a .doc extension). |
Description of the need
This came from reading several other issues about various problems with image uploads, and realizing that we do not have a dedicated form API element for images. We currently have only
file
andfile_managed
.Images usually need different validation criteria than generic files, including
In most places in core, these are added manually to every file upload field used only for images. A new
image
form API element would make it easier for core developers change all image API elements at once. For example, adding a file type validation that used a site-wide set of allowed image types:webp
to default extensions on new image fields (if supported) #4998There are also other image-only upload locations in core, such as the site logo and favicon (and there may be others).
Proposed solution
Add a new
image
form api element, that is identical tofile
but with additional validators.Alternatives that have been considered
Helper functions that could be used to determine a default set of allowed file types, based on the operating system and modules.
Draft of feature description for Press Release (1 paragraph at most)
Backdrop now includes a new form API element specifically for images, that will natively support all image types supported by your system.
The text was updated successfully, but these errors were encountered: