Earlier today I was given the task of making a filefield in a CTools Content Type (I.e., a panel) admin form accept multiple items. I figured plupload would be the easiest way to do this, and so went about doing so. For an idea of what I'm doing, check out this tutorial.

The better part of a day later, here are some findings:

a. Form handling in a CTools plugin is somewhat different than in a normal module.

b. For some reason, plupload's CSS would simply not work. I had to use the following block of awful code to make it work:
[Snipped]
Edit: The way I had it before was breaking plupload UI images. I was placing the drupal_add_css/ctools_add_css call too late in the execution chain. Kind of annoying it wouldn't enqueue by default, but nothing too complex.

c. I can't get the description field to say anything except all the default filetypes available to Drupal. I think this is because #description is passed to theme(), which I'm guessing CTools doesn't use for its admin forms. Any idea how to get around this (Beyond hiding the whole thing with CSS)? Edit: missed the "file_validate_extensions" option.

d. It doesn't seem like plupload is adding anything to file_managed. I have no idea why this is. Any help?

e. Is there any way to call a function after each image upload? I tried using the patch at http://drupal.org/node/1715374#comment-6328588 but I can't seem to get that hook to work. Ultimately I need to rebuild the entire form after each upload (The plugin displays previous images in the table like Media -- though not through Media). Edit: I was able to get that hook to work, though I'm still not sure how to set $form['rebuild'] when that hook doesn't really take anything form-related.

Thanks!

Comments

Issue summary:View changes

Edit: missed the "file_validate_extensions" option.

Issue summary:View changes

Edit - I was able to get that hook to work.

As you can see, I've made some progress with this. Alas, I'm having problems with temporary files, which is where stuff is seemingly dying. Using the hook I reference in the issue, I added a watchdog call to get the paths of various stuff. When I go to:

http://localhost/plupload-handle-uploads?plupload_token=213dAajsbt_aDfx6...

(Or whatever the relevant token is)

...I get the following message:

{"jsonrpc" : "2.0", "error" : {"code": 105, "message": "Invalid temporary file name."}, "id" : "id"}

This is also after trying to upload stuff via http://localhost/plupload-test

Really, at this point, I think the only thing that's different in using plupload as part of a Panel/CTools content type is that you have to manually enqueue CSS. Feel free to rename the issue if you think the scope of it has changed sufficiently to warrant such.

However, I'm still unable to save content to the file_managed table and can't seem to get past the "temporary" stage (Though note images are transferring to /tmp -- so they are in fact uploading).

Any thoughts? Thanks!

Status:Active» Closed (works as designed)

Wow. Everything now works...

Is there any way to auto-submit the form after the images have uploaded? I completely failed to notice the "Submit" button at the bottom of plupload-test -- either I'm a total idiot, or that's not the most intuitive UI design (I'm not entirely sure which at the moment, TBH).

Wicked module, let me know if you need help with documentation (I've already made a few fixes to the main documentation page).

Nice to hear that! I am sorry for a late reply. I was really busy...

Is there any way to auto-submit the form after the images have uploaded?

I think that media 7.x-1.x implements this. Maybe you could check how it's done there.

Wicked module, let me know if you need help with documentation (I've already made a few fixes to the main documentation page).

Thank you for all your contributions. Every contribution is more than welcome, of-course.

Issue summary:View changes

Edit -- The way I had it before was breaking plupload UI images. I was placing the drupal_add_css/ctools_add_css call too late in the execution chain. Kind of annoying it wouldn't enqueue by default, but nothing too complex.