Problem/Motivation
We duplicate the same logic of getting uploaded files from the request in four different locations:
file_save_upload()file_managed_file_save_upload()\Drupal\config\Form\ConfigImportForm::validateForm()- (\Drupal\Core\Render\Element\File::valueCallback())
Steps to reproduce
N/A
Proposed resolution
Create a UploadedFilesExtractor::extractUploadedFiles() and remove the duplicate code.
After review, the fourth usage in \Drupal\Core\Render\Element\File::valueCallback() is different and strange and is not converted here, as it returns the object cast to an array. That might need to be changed to something more useful, but that's not in scope of this issue.
Remaining tasks
Check the last sentence of the change record and the use of $form_field_name
User interface changes
N/A
Introduced terminology
N/A
API changes
Added a new service UploadedFilesExtractor::extractUploadedFiles()
Data model changes
N/A
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3555115
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
Comment #3
kim.pepperComment #4
smustgrave commentedWould this count as an API change? If it should get an MR.
Moving to NW as a number of functional tests seemed to fail.
Comment #7
nicxvan commentedRebasing on main so we can see what the actual failures are.
I think this should be a service, passing in the current request seems wrong since every use requires that.
Comment #8
nicxvan commentedOk I converted it to a service and identified the error:
Comment #9
kim.pepperThanks for picking this up. I'm not sure why UploadedFile is now getting serialized with the form data.
Comment #10
nicxvan commentedI did confirm that the same error occurs before I changed it to a service as well, so it shouldn't be my changes.
Comment #12
berdirSee my comments on the MR.
Comment #13
smustgrave commentedSeems to still have some test failures unfortunately.
Comment #15
berdirIssue summary needs an update, \Drupal\Core\Render\Element\File::valueCallback() is no longer updated because that's different and weird.
maybe needs a change record?
That makes this a bit less useful as there's fewer places to unify, but I guess still useful as we build on it in the related issue?
Wondering if it would be cleaner/easier to test if request would be passed in to the method instead of the indirection with the request stack, but I think this is pretty common for us and I'm probably influenced by a recent book I've read.
Comment #17
mohit_aghera commentedThanks for the feedback @berdir
- I've added a change record here https://www.drupal.org/node/3591900
- Issue summary updated.
I saw the commits and the changes in
\Drupal\Core\Render\Element\File::valueCallback()have been reverted, so something might be awful there.Just curious, which book you are talking about?
Comment #18
mohit_aghera commentedComment #19
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #20
smustgrave commentedComment #21
berdirI updated the CR and issue summary a bit more, looks good to me.
> Just curious, which book you are talking about?
https://codethatships.com/
Comment #22
quietone commentedI read the comments, the MR and the change record. I have updated credit.
The last sentence of the change record refers to
$form_field_namewhich is not used in the the change record. Is something missing from the change record? Setting to needs work for that.Comment #23
mohit_aghera commented@quietone, this looks like a typo change.
I checked the diff here https://www.drupal.org/node/3591900/revisions/view/14360985/14364088 and it seems a typo.
I've updated the change record.
Comment #24
nicxvan commentedThanks @quietone! Feedback has been addressed!