The current workflow when files are added is like this:
* Add the file (through the add form or media browser widget.
* The file is added, and the entity has been created.
* You can now edit the entity, when you add the entity through the add form, you get to the edit form immediately.
There are some problems with this, primarily since we actually can add files without inputting required fields. I propose that we change this to a two-step process:
1. The file is uploaded through the form, and we refresh the form through AJAX (with fallback of course). We don't store the file entity at this point.
2. Once we know what file we are dealing with, we know which bundle it should be associated with. This means we can attach the proper field form form using the right bundle, and all the normal validation can occur.
Step one needs to be pluggable somehow, since not all uploading methods involve uploading a file, like selecting a youtube video. We also need to store a reference to the file that we just uploaded so that we can delete it (on cron) if the field data is not validated.
Comments
Comment #1
fabsor commentedChanging title
Comment #2
dave reidYeah I like the idea of making this a multi-step process that maybe skips itself if there are no fields available. If we store the file entity with $file->status = 0, this means the file is temporary, and we can change $file->status = FILE_PERMANENT when the user completes step 2. System module automatically cleans up and deletes temporary files.
Comment #3
gmclelland commentedrelated discussion #1426730: Automatically open the file edit modal after uploading a file in the media module issue queue
Comment #4
tsvenson commentedTagging
Comment #5
mauritsl commentedThe patch adds a multi-step wizard for adding files. This wizard now always consists of three steps:
There is only one filetype to choose from until #1292382: Make it possible to create any number of custom File Types has been fixed. Note that the file is saved directly after uploading, without knowing the correct filetype yet. This patch overwrites $file->type before saving. This change is not yet saved in the file object, which will be fixed by #1637382: type of file is overwritten in file_entity_file_presave()..
Todo's:
Comment #6
mauritsl commentedPatch attached skips steps 2 and 3 if not applicable and integrates with the File Access API.
Required patches before applying this patch:
- http://drupal.org/node/1292382#comment-6122536
- http://drupal.org/node/1227706#comment-6121346
Comment #7
tsvenson commentedFYI, we had an interesting brainstorming about improving the UX/usability of adding one or multiple files to a Drupal site in Barcelona. Basically we came up with a way of just having one modal screen and a dynamic AJAX driven interface.
It's one of things I got on my now even longer todo-list to type up. Expect it within the next week or so.
Comment #8
mauritsl commentedAh, you recovered from the weekend :)
The patch already needs to be changed since the multiple file types thing is also changing. Let me know when you wrote it all down so we can continue the discussion.
Comment #9
tsvenson commentedWell, sort of recovering. Its easy since meeting so many great people at events like this is really energizing.
I'll post here when I have got to writing it up. Thanks for your great help.
Comment #10
klonos@tsvenson, #7:Hey Thomas! Did you manage to make some time to perhaps file an issue I can follow on that modal screen + dynamic AJAX driven interface you talked about in Barcelona?
Comment #11
tsvenson commented@klonos: Not yet. I'm currently working on a bigger document that covers much more. Hope to have a first draft ready in a week or two.
Comment #12
gmclelland commentedCross referencing #1678106: Mobile Friendly Media Browser
Comment #13
spesic commentedRerolled patch in #6 against HEAD. Also, note to testers - run drush updb
Comment #14
svajlenka commentedI tested the patch in #13 after applying the previous patches. It seemed like there was an issue where if a file that was uploaded had multiple applicable file types, you could select the filetype fine, but if it had any associated fields, the form would skip the entry of those fields. I've attached a modified version of #13's patch to correct this behavior.
Comment #15
mauritsl commentedThe wizard seems to work fine, but renamings in file_entity causes troubles in media module which makes testing a bit harder.
One thing that doesn't work fine is the ctools model popup. The popup doesn't close after finishing the form. I tried removing the redirect and dived into the ctools code, but couldn't get rid of the pesky popup...
Anyway, I've renamed file_access() to file_entity_access() to make this compatible with the latest patches from #1227706: Add a file entity access API. I also changed the label for filetype. There was a "@todo" there to replace it show the label instead of machine name. It's replaced by a call to entity_label().
Note that the access api patch is still a dependency. I used the following patch for testing:
http://drupal.org/node/1227706#comment-6623878
Comment #16
mauritsl commentedForgot to mention, the problem with the popup is on the popup used for adding files from the media selector field (on a node edit page), not on the content -> files tab.
Comment #17
tinker commentedTested patch from #15 using latest media 7.x-2.x-dev. #1227706 is comitted so did not have to apply patch. Remember to update db and clear caches if upgrading Media or File Entity as there are many function changes.
Working great for me. Please note if you are a user who can edit the uploaded file you will be redirected to the edit modal after file upload. This is set by the Media module so if that is an issue it should be opened there.
Comment #18
mauritsl commentedComment #19
raspberryman commentedentity_label() was returning $file->filename, which was a bit confusing. I've hooked a label callback into the entity to help clarify Step 2 of the upload wizard.
Comment #21
raspberryman commentedAhh, no on 19 - there is an existing implementation of entity_label() that seems to make sense (see
file_entity_edit_submit()). Instead, I moved this back over to type, but this time withfile_entity_type_get_name().Comment #22
raspberryman commentedComment #24
mauritsl commentedOk, setting status to start test.
Comment #25
mauritsl commentedcrossposting..
Comment #26
raspberryman commented#21: file_entity-multi_part_form_upload-1054616-21.patch queued for re-testing.
Comment #27
raspberryman commentedhaha mauritsl, I'll stop pressing buttons :) We're in a race condition.
Comment #28
raspberryman commentedSince this module has a dream of core, I'm thinking we shouldn't extend this wizard to support plupload. Currently, there is no multiple file upload support in this wizard patch. Should we invest in this direction as well? Or... commit this patch for single uploads, and open a new issue for multiples?
Comment #29
mauritsl commentedThere is already a ticket for that: #1599892: Plupload integration broken
I suggest committing this single file upload thing, after we have done a little more testing.
Comment #30
raspberryman commentedIn the interest of testing - I added two test cases with a handful of steps each for this feature.
Comment #31
mauritsl commentedYou're a hero!
I tested adding files using both the file tab and the media browser (wysiwyg plugin). Everything works well.
Only one thing in the media browser.. It redirects to the edit page after a file has been added. That redirect should now be removed, but this is in the media module, not file_entity. I suggest to open an issue there after this has been committed.Tinker already said this in comment 17 :)Marking this patch as RTBC.
Comment #32
raspberryman commentedRerolled against recent commit: http://drupalcode.org/project/file_entity.git/commit/11894c1
Also, tossed in a couple minor Coder recommendations and fixed a spelling error.
Comment #34
raspberryman commented#32: file_entity-multi_part_form_upload-1054616-32.patch queued for re-testing.
Comment #35
raspberryman commentedThere we go!!
Comment #36
ParisLiakos commentedJust a quick look
any reason why we are not using http://api.drupal.org/api/drupal/modules%21field%21field.info.inc/functi... here?
why adding indentation?
same..also comma is removed from '%title'
Comment #37
mauritsl commentedThanks for the review. I've fixed these coding style errors and use field_info_instances instead. There is no reason for the custom function.
Comment #38
mauritsl commentedCan confirm that the flow still works good using field_info_instances().
I leave it to someone else to give the RTBC now ;)
Comment #39
raspberryman commented#37 applied and passed :)
Comment #40
claudiu.cristeaNon functional review.
Remove trailing spaces where ¶ symbol appear. Not critical but it should match coding requirements.
Comment #41
raspberryman commentedRerolled #37 against #32, passes Coder minor, improved docs, removed trailing commas.
Comment #42
mauritsl commentedNo functional changes, but did a sanity check to see if everything still works.
I can confirm that it does not add minor issues in coder.
Comment #43
ParisLiakos commentedThis looks good:)
Adding indentation again.
Removing comma
Removing comma
same
same
same
Comment #44
mauritsl commentedFixed issues from #43. No functional changes.
Comment #45
michaelmol commentedTested patch. Patch is clean and functional
Comment #46
ParisLiakos commentedOk, looks good, has tests, i love it, what more is needed?
I commited this. Could someone open an issue to media queue to remove the edit screen after uploading a file? i guess it is not needed anymore;)
Thanks all!!
Comment #47
ParisLiakos commented#1848034: Remove ctools edit form after uploading a new file in media browser
Comment #49
azinck commentedThis change doesn't allow the File Name of the new file to be edited in the upload flow; only the "normal" fields are available for editing. Is this an oversight? Editing of the file name was previously supported at the time of upload when this functionality was handled by Media.
Comment #50
jienckebd commentedIs it possible to disable this multi-step feature if we want the file uploading process to be one step? I imagine that some situations won't call for multiple steps like this.
If not, I can try to work up a patch. I'm just checking if it's already built.
Comment #51
mauritsl commentedThe idea is that steps will be skipped when not applicable. That is, if you upload an image, you should not be asked to select the file type when there is only one file type for images. And when it doesn't have additional fields, another page will be skipped as well. So when a situation "does not call for multi-step", it shouldn't be, automatically.
Comment #52
kiwad commentedWorks well when you upload a new file, but unfortunatly doesn't seem to be the case if you add a file from Web URL... or am I missing a configuration somewhere ?
Comment #53
azinck commentedPer my complaint in #49, here's a new bug #2074625: Allow filename (and possibly other attributes) to be edited during upload process
Comment #54
Ratul Saha commentedIs it possible to skip the next step of adding fields attached to the files and simply be done with creating the (file) entities?
With Pulpload and bulk upload, the editing area can become real long and unnecessary for some usecase.