We should implement a simple upload form to simplify uploading files without selecting specific media types. While media functionality in Drupal 8 doesn't always involve uploading files, we could simplify it - user usually doesn't need to select media to type when uploading an image or pdf document, we can automate that by matching file extensions with media type configuration (upload fields have a list of allowed extensions).
Although there are cases when there might be multiple image type media types, this can be solved by configuration - e.g user can select the types which will be used for extension matching. We can keep all the media type tabs, just add one additional tab or a combined version where we hide types that can be uploaded through that form.
Sometimes there is a need to upload multiple types of files - this basically simplifies uploading files - the user doesn't need to select specific media type and just select the files from the computer and the backend does all the work.
We could use DropZonejs here to create a nice upload field.
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | Screenshot from 2020-04-15 23-27-59.png | 26.86 KB | ytsurk |
| #23 | combined-upload-3103489-23.patch | 25.08 KB | ytsurk |
| #20 | combined-upload-3103489-20.patch | 24.42 KB | rang501 |
| #17 | combined-upload-3103489-17.patch | 24.29 KB | rang501 |
| #11 | combined-upload-3103489-11.patch | 22.2 KB | ytsurk |
Comments
Comment #2
rang501 commentedComment #3
ytsurkYes - actually I like this feature and also use it.
dropzonejs is the module of choice, yes.
But there is also something planned in core, see #2113931: File Field design update: Upload field.. Seems stuck right now #3064084: Create accessible markup for a drag & drop file upload widget (and ensure there is an accessible alternative interaction).
I'm not a fan of having lots of module dependencies. dropzonejs will just work if installed anyway right now, but per media type.
Maybe we could change the feature to having just one upload field?
Comment #4
rang501 commentedYes, we could at first just add a simple upload field to upload all allowed file types.
I have done this before, so I could try to add it to this module.
Comment #5
rang501 commentedInitial work. I named it combined upload. It seems to be working, although it needs testing, maybe I missed something.
Comment #6
ytsurkNice work Rang, thanks!
I really like the approach, and also that is is enablable (not enabled by default).
I now started altering the media_directories config form (see #3104856: Adapt changes from media_library and theme system to the quick-edit dialog - and for the editor module I did a commit introducing this right before). We should decide for either solution (Form/Tab per module or all-in-one - I vote for all-in-one for now).
In your patch the route is missing :(
Also the form does not show up, the MediaDirectoriesController::mediaAdd does not respect the new setting, I stopped trying to fix that now ;)
Comment #7
rang501 commentedThis new patch should make it work nicely. It depends a bit on #3118805: AddForm's remove link not working, maybe some kind of reroll or merge fix is needed when we need to merge these two things.
The configuration form is still on a separate route. I don't think it's a major issue, for now, merging the two pages need some things to consider, like translating configuration (we might need that in future)
Comment #8
rang501 commentedReroll of the patch to use committed fix in #3118805: AddForm's remove link not working. I also found settings form cleared cache on save and fixed that and while doing that I moved the settings to the existing form.
Comment #9
rang501 commentedPatch reroll.
Comment #10
ytsurkWell done!
First I thought of restricting the types on the edit form, but the field type can be custom, and shall be left open.
I have added a proper default value for the media types.
Comment #11
ytsurkI also removed the dedicated upload location.
Comment #12
rang501 commentedUpload destination is still needed, it is different for each media type which means it is not possible to set the final location for that upload field. We need to save files temporarily into the public folder and move the file after uploading by using media type settings.
Comment #13
ytsurkSorry for marking an un-tested patch to RTBC.
And thanks for setting this up. I would suggest to use the tmp: uri scheme, not exposing the files (if only for 10s) to the public as they may be private.
Comment #14
ytsurkComment #15
ytsurkInjecting the file system and removed unused imports.
Comment #16
rang501 commentedIt is possible to create a submodule, we can think about it later, but about the moving part - temporary doesn't work correctly, it is not possible to generate image thumbnail so the user sees only grey box :)
I think uploading directly to the public or some special subfolder is most likely the best solution here.
Comment #17
rang501 commentedI think I fixed it - there is a method called processInputValues which can be used to move files to the right place before generating edit form (the form after upload), it seems to be working quite well.
About moving into separate module - it is a bit hard to do - need to override controller, preprocess hook, config schema, so I would keep it integrated into media_directories_ui module, we can think about it in 2.x version.
Comment #18
ytsurkThanks for your quick reply here, @rang501.
Nice change! Works well and thumbnails are created.
Comment #19
ytsurkRe-rolled against latest -dev
Comment #20
rang501 commentedCombined upload form class needed some fixes.
Comment #21
ytsurkLooks good and works :D
2 more questions here:
Why is video not added to the combined upload?
And should we inform the user about this setting?
Comment #22
rang501 commentedThe video (core media type) should work if it is using the file field type for uploading
One thing I forgot to implement was to take out media types that can't use combined upload functionality (i.e oembed) on the settings form. This new patch should work as expected. The field description should be informative enough.
Comment #23
ytsurkSorry .. got existing config in the database. So this will be disabled by default ...
Thanks for the setting form type exclusion!
I changed the tab title a bit, putting the type names there - you can remove that if you don't like it ..
And renamed the setting to be more clear.
Pls commit that!
Comment #24
ytsurkSo here a screenshot of the title change
Comment #26
rang501 commented