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.

Comments

rang501 created an issue. See original summary.

rang501’s picture

Issue summary: View changes
ytsurk’s picture

Yes - 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?

rang501’s picture

Yes, 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.

rang501’s picture

StatusFileSize
new12.64 KB

Initial work. I named it combined upload. It seems to be working, although it needs testing, maybe I missed something.

ytsurk’s picture

Assigned: Unassigned » rang501
Status: Active » Needs work

Nice 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 ;)

rang501’s picture

Title: Autodetect media type on upload (simple upload form) » Autodetect media type on upload (combined upload form)
Status: Needs work » Needs review
StatusFileSize
new23.16 KB

This 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)

rang501’s picture

StatusFileSize
new21.36 KB

Reroll 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.

rang501’s picture

StatusFileSize
new22.3 KB

Patch reroll.

ytsurk’s picture

Assigned: rang501 » Unassigned
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new22.35 KB
new743 bytes

Well 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.

ytsurk’s picture

StatusFileSize
new22.2 KB
new1.26 KB

I also removed the dedicated upload location.

rang501’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.2 KB
new23.39 KB

Upload 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.

ytsurk’s picture

StatusFileSize
new938 bytes
new23.39 KB

Sorry 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.

ytsurk’s picture

BTW - This also could be a module at it's own ..

ytsurk’s picture

StatusFileSize
new24.87 KB
new3.84 KB

Injecting the file system and removed unused imports.

rang501’s picture

Status: Needs review » Needs work

It 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.

rang501’s picture

Status: Needs work » Needs review
StatusFileSize
new2.06 KB
new24.29 KB

I 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.

ytsurk’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for your quick reply here, @rang501.

Nice change! Works well and thumbnails are created.

ytsurk’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new24.21 KB

Re-rolled against latest -dev

rang501’s picture

StatusFileSize
new24.42 KB
new1.96 KB

Combined upload form class needed some fixes.

ytsurk’s picture

Looks 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?

rang501’s picture

StatusFileSize
new24.65 KB
new751 bytes

The 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.

ytsurk’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new25.08 KB
new5.1 KB

Sorry .. 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!

ytsurk’s picture

StatusFileSize
new26.86 KB

So here a screenshot of the title change vertical tab title change

  • rang501 committed f52bd1d on 8.x-1.x
    Issue #3103489 by rang501, ytsurk: Autodetect media type on upload (...
rang501’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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