Problem/Motivation

As part of #3221796: [META] Modernise file upload logic we are removing duplicated logic in the different ways files can be uploaded.

The following classes define a way to get file upload validators from settings using (almost) identical logic.

  • \Drupal\file\Plugin\Field\FieldType\FileItem::getUploadValidators()
  • \Drupal\file\Plugin\rest\resource\FileUploadResource::getUploadValidators()
  • \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::getUploadValidators()
  • and in contrib \Drupal\graphql\GraphQL\Utility\FileUpload::getUploadValidators()

Note: we can't use inheritance as there are different ways files can be uploaded (i.e. form vs input stream).

Steps to reproduce

Proposed resolution

Provide a trait that these classes can use to get file upload validators from settings.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3389447

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kim.pepper created an issue. See original summary.

kim.pepper’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record

Change looks good. Can we get a CR to announce the new trait?

kim.pepper’s picture

Status: Needs work » Needs review

Had a thought that we may need to add a trait for getImageUploadValidators() as code is duplicated between ImageWidget and CKEditor5ImageController. Created #3389675: Provide a trait to create image upload validators from settings for that.

Renamed the trait method to \Drupal\file\Validation\FileValidatorSettingsTrait::getFileUploadValidators() for clarity.

Added a CR.

kim.pepper’s picture

Issue tags: -Needs change record
kim.pepper’s picture

Priority: Normal » Critical

Blocking a critical #2940383: [META] Unify file upload logic of REST and JSON:API therefore this is also critical.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Trait short and sweet haha. Looks good though.

quietone’s picture

I'm triaging RTBC issues. I read the IS and the comments. I didn't find any unanswered questions or other work to do.

Leaving at RTBC.

kim.pepper’s picture

Title: Provide a trait to create file upload validators from settings » Provide a trait to create file upload validators from file field settings
larowlan’s picture

Status: Reviewed & tested by the community » Needs review

Let a comment on the MR clarify

+1 for the new title

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC after reply to my question. No code change so just reinstating #8

  • larowlan committed 82c59f84 on 11.x
    Issue #3389447 by kim.pepper, smustgrave, quietone: Provide a trait to...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 11.x
Published the change record.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.