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
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:
- 3389447-provide-a-trait
changes, plain diff MR !4866
Comments
Comment #3
kim.pepperComment #4
smustgrave commentedChange looks good. Can we get a CR to announce the new trait?
Comment #5
kim.pepperHad 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.
Comment #6
kim.pepperComment #7
kim.pepperBlocking a critical #2940383: [META] Unify file upload logic of REST and JSON:API therefore this is also critical.
Comment #8
smustgrave commentedTrait short and sweet haha. Looks good though.
Comment #9
quietone commentedI'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.
Comment #10
kim.pepperComment #11
larowlanLet a comment on the MR clarify
+1 for the new title
Comment #12
larowlanBack to RTBC after reply to my question. No code change so just reinstating #8
Comment #14
larowlanCommitted and pushed to 11.x
Published the change record.