I need to detect how/where a file was selected in a hook_node_presave so I can generate a specific taxonomy, and thus have the media_browser_plus module create an associated folder structure, and finally move the file to that new folder. However, I need to do this only for new uploads, not files selected from the library. I've not been able to determine the best approach for this. Can the file source be detected from the $node object in a hook_node_presave, or does it have to happen in the submit of a form via $form or $form_state?

I'd appreciate any code samples anyone can offer.

Thanks in advance.

Comments

das-peter’s picture

how/where a file was selected

Could you please elaborate what this means? The field it is stored in?

I need to do this only for new uploads

Well I guess you should hook into file uploads then / or maybe the file entity form. And have a submit handler that just acts on creation and not on update.

jmev’s picture

I need to know if a file was selected by browsing for a new file, or by using the media browser. I want to carry out some specific functionality based on that, which is to create a taxonomy for the current node, following which the media_browser_plus module will create a directory structure, and then I need to move only newly uploaded files (not those selected from the media browser library) to the new directory. I don't know if the file uploads process will allow for this. The hook_file_insert description says "The hook doesn't distinguish between files created as a result of a copy or those created by an upload", so I didn't think it would be useful.