Rationalize image widget validation error messages

Created on 5 February 2018, almost 7 years ago
Updated 17 March 2023, almost 2 years ago

Problem/Motivation

After commits of 🐛 Allow image fields to use any extensions the current image toolkit supports (instead of hard-coding jpg, png and gif only) Fixed and #2377747: Incorrect node create validation error when an invalid image is attached to a field , uploading of image files to image fields is much more controlled and flexible.

However, now if we try to upload a file with an extension that is not supported, we have a bit of info overload, see below.

This is because we have two separate validation steps:
a) the extension validation (that compares vs the extensions allowed for the image field in its settings)
b) the image validation (that compares image validity vs the image formats supported by the underlying toolkit)

The two steps are independent, and if you try upolading a file that is netiher in the extensions configured for the field, nor supported by the toolkit, two sub-messages are displayed, each one for its checks.

Proposed resolution

1) Make the file_validate_is_image validator aware of the extensions defined for the field.
2) If the extension of the file being uploaded is not one of those configured for the field, let the file_validate_is_image validator skip its check, because even if it passes, still the file_validate_extensions validator will fail.
3) If no extensions are configured for the field, then file_validate_is_image should validate against all the image formats the underlying toolkit is supporting.

Screenshots

:

Before the patch -

1) Try uploading a file with extension different from the configured ones. We have two separate sub-messages, with diverging info about allowed types.

2) Try uploading an invalid image file. One sub-message only, but allowed types are different than the configured ones.

After the patch -

3) Try uploading a file with extension different from the configured ones. One sub-messages, with info about allowed types conistent with configuration.

4) Try uploading an invalid image file. One sub-message, with info about allowed types conistent with configuration.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs work

Version

10.1

Component
Image module 

Last updated 10 days ago

Created by

🇮🇹Italy mondrake 🇮🇹

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇮🇹Italy mondrake 🇮🇹

    Rebased and changed to MR workflow.

  • Status changed to Needs review almost 2 years ago
  • @mondrake opened merge request.
  • Status changed to Needs work almost 2 years ago
  • Status changed to Needs review almost 2 years ago
  • Status changed to Needs work almost 2 years ago
  • 🇺🇸United States smustgrave

    Tried replicating on Drupal 10.1
    Configured the Article image field to only accept gifs
    When I create an Article and upload a png I get "The selected file Screen Shot 2023-03-16 at 1.09.03 PM.png cannot be uploaded. Only files with the following extensions are allowed: gif."

    There a step I'm missing?

Production build 0.71.5 2024