While Plupload Integration for 6.x currently has a modest feature set, I feel this patch does a lot to allow developers to do a lot more with the module without actually having to build out the feature set of the plupload module "core".

Why the presave hook?
-The presave hook allows a developer to create logic-based, or settings based, way of filling out other node fields, taxonomy, etc

Why the postsave hook?
-The $node object in the post save hook contains a full picture of the node, (including the nid) This hook allows a developer to do *something* that that node after its creation. (something like, create a node reference to the new node from an existing node)

Why does this have to be here--why not use the nodeapi?
-I want to only do these things to the nodes created through the plupload tool, I want my content administrators to be able to create the same type of node. through the node/add form, and not have all of this other *magic* stuff happen.

Thanks Loads!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greggles’s picture

This looks great to me!

I'd like to add more parameters to each call, perhaps a $options as an array or something, so that we can send in more data.

My dream is that at /file-plupload we could add parameters like /file-plupload?terms[]=1,5,60?gids[]=99 And then a module would add taxonomy terms 1, 5, 60 and OG could add the group 99. To do that cleanly we should add hooks like you suggest and give them some more data.

greggles’s picture

Status: Needs review » Needs work
vordude’s picture

What data does this $options array hold by default? If you want to pull the data out of the url, it could be done in the other module inside of the basic hook, no?

greggles’s picture

I don't think so.

There's the /file-plupload?tids[]=1,2,3 URL. That has the parameters in it.

But the actual URL that gets the files is just "plupload-pernode" without any parameters.

What we need to do is add the tids into the headers

headers
Name/value object with custom headers to add to HTTP requests.

I don't expect your patch to fix all that, but we should at least build these hooks with the ability to handle extra $options.

justintime’s picture

Just a note that you can use nodeapi to do operations on just plupload added nodes by adding this to the presave op:

        $item = menu_get_item();
        if ($item['path'] == 'plupload-pernode') {
          // do stuff
        }

The approaches above are more clean, but my approach is a workaround until such a feature is implemented.

justintime’s picture

I'm thinking that with the inclusion of #919482: create ability to assign parameters in the url, implement taxonomy term as an example, we don't need these hooks any longer. Here's an example of how you can achieve what Vordude wants without any hooks. If you're using the included file-plupload page, just link to it like so: 'file-plupload?drupal_pluploaded=1'

If you're calling the plupload_upload_page function within your module, pass it this:

array('drupal_pluploaded' => TRUE);

Now, in nodeapi (prepare and save for your pre and post hooks), you can simply say:

if ($node->pluploaded) {
  // do stuff
}

We can certainly implement hooks if need be, but I think at this point it just is duplicating existing features. Thoughts?

vordude’s picture

Please don't write the idea off yet.

I'll soon be working on an extension module for plupload that does other "stuff" (cck widget/form element) with the tool, extending the initial basic 'core' implementation.

I can see that for this to work, plupload will need to stay flexible in how data needs to be passed around, I haven't had the chance to flesh this out in its entirety.

You're right, the Node API, can handle this (at this point). But IMHO the hooks provide a cleaner interface for developers to do what they like before and after the node is created.

greggles’s picture

Title: Patch adding Node Hooks to Plupload » Adding presave/postsave hooks to Plupload

I think more hooks are better than fewer. If we add in the $options that is created in #919482: create ability to assign parameters in the url, implement taxonomy term as an example then I think this patch is ready to go.

justintime’s picture

Hadn't thought of the sub-module thing - agree. I'll commit #919482: create ability to assign parameters in the url, implement taxonomy term as an example today if you want to reroll your patch.

justintime’s picture

Status: Needs work » Needs review
FileSize
613 bytes

OK, I'll bite. Here's a re-rolled patch with the options passed in.

vordude’s picture

FileSize
611 bytes

Actually when I rolled this to begin with, I'm pretty sure the &$node is wrong.

If you're going to pass it by reference it should be done in the function definition not here.

Pretty sure php will puke warnings if you have it in the module_implements...

justintime’s picture

Heh, you're right. That'll teach me to create patches when on Nyquil :)

AFAIK, call-time pass by reference is a warning in PHP <= 5.2, but an error in 5.3+.

Have you actually tested the patch? I'd have to code up a dummy hook to test it.

justintime’s picture

Committed to 6.x dev: #914252 by vordude, greggles, justintime: Adding presave/postsave hooks to Plupload

justintime’s picture

Status: Needs review » Fixed

Forgot to mark as fixed.

Status: Fixed » Closed (fixed)

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

brunorios1’s picture

subscribing...

greggles’s picture

brunorios1 - why are you subscribing to an issue that is "closed - fixed."

If it's broken or you need something please say what it is.

brunorios1’s picture

sorry, was a mistake...