FileUploadHelp preprocessor was broken by Core's change to constraint plugins

Created on 2 January 2024, 6 months ago
Updated 21 June 2024, 6 days ago

After updating to Drupal Core 10.2.0 the file upload size and allowed file type constraints disappeared from the "Upload requirements" dropdown under File field widgets. This is the result of a change to Core's file validation and constraint plugin system, see the change record at https://www.drupal.org/node/3363700 โ†’ and its subsection on "Form API changes."

As described in the change record, the render array keys that contain the constraint information have changed. The preprocessor class needs to be updated to check for these new keys. It should be possible to do this in a backward-compatible way by checking for both the old and new keys.

Steps to reproduce:

  1. Install Bootstrap.
  2. Either set Bootstrap to be the admin theme or in the Appearance admin settings uncheck the box to "Use the administration theme when editing or creating content."
  3. Add a file field to any content type. Constrain the field to one or more file types. The default Article type with its Image field works.
  4. View the form for adding or editing the content type.
  5. Click the "Upload requirements" link under the file field widget.

Expected result:
The upload requirements should display the cardinality, file upload size limit, and required file types.

Actual result:
The upload requirements only displays the cardinality.

๐Ÿ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States dcam

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

Merge Requests

Comments & Activities

  • Issue created by @dcam
  • Merge request !33Updated FileUploadHelp with new validator keys โ†’ (Merged) created by dcam
  • Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update 6 months ago
    Waiting for branch to pass
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dcam

    The image resolution constraint description should be broken too, but I don't have the ability to test that in my current environment.

  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dcam

    Setting to NW based on comment #3.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dcam

    It's still NW due to #3, but I tested the MR on a 10.2.0 site and a 10.1.x site. The constraint text appeared correctly on both sites. So the BC code works and you shouldn't have to release a new major version.

  • Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update 6 months ago
    Waiting for branch to pass
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dcam
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dcam
  • Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update 6 months ago
    Waiting for branch to pass
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dcam

    I added the image size keys. Unless I'm mistaken, this should take care of all the issues.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dcam
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia pooja saraah Chennai

    pooja saraah โ†’ made their first commit to this issueโ€™s fork.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    last update 6 months ago
    Build Successful
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dcam

    @pooja-saraah can you explain why you made these changes? This was a simple big fix. But it looks like you've introduced a bunch of code formatting changes just because. Now the MR is more difficult to review and less likely to be applied. The Drupal community has a long-standing practice of keeping unrelated changes out of patches. Unrelated changes are confusing and make it more likely to cause merge conflicts for other pending patches. Unless you were fixing an additional problem with the code, then please do not go around editing existing MRs. Open follow-up issues to make your edits. And if you were fixing something, then please explain what that problem was.

  • Open on Drupal.org โ†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 5.7
    last update 3 months ago
    Waiting for branch to pass
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dcam

    The changes introduced by @pooja-saraah resulted in a WSoD with the following error:

    The website encountered an unexpected error. Try again later.

    Error: Call to undefined method Drupal\bootstrap\Plugin\Preprocess\FileUploadHelp::getRenderer() in Drupal\bootstrap\Plugin\Preprocess\FileUploadHelp->preprocessVariables() (line 133 of themes/contrib/bootstrap/src/Plugin/Preprocess/FileUploadHelp.php).

    @pooja-saraah never responded with an explanation of why their changes were made. So I reverted their changes as being both unnecessary and harmful. As a module maintainer myself, I would remove their credit on this issue for those reasons.

  • First commit to issue fork.
  • Pipeline finished with Skipped
    6 days ago
    #205043
  • Status changed to Fixed 6 days ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States shelane

    Thanks.

Production build 0.69.0 2024