Clone Node with File Attachments
I understand that the current node_clone.module does not support file attachments. I would like to clone a node, and if the node has file attachments, copy those attachments to the new node. Can someone point me in the right direction on this? Thanks. -ron -- Ron Parker Software Creations http://www.scbbs.com Self-Administration Web Site http://saw.scbbs.com SDSS Subscription Mgmt Service http://sdss.scbbs.com Central Ave Dance Ensemble http://www.centralavedance.com R & B Salsa http://www.randbsalsa.com
I actually figured out how to get the file attachments from the original node to appear on the submission form for the new node: /** * Implementation of hook_prepare(). */ function agenda_prepare(&$node) { if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'clone') { $orig_agenda = node_load(arg(1)); $node->files = $orig_agenda->files; } } HOWEVER, when I click on the "submit" button and save the new node, the file attachments do NOT appear. Can someone tell me what I'm missing here? Thanks! -ron Ron Parker wrote:
I understand that the current node_clone.module does not support file attachments.
I would like to clone a node, and if the node has file attachments, copy those attachments to the new node. Can someone point me in the right direction on this?
-- Ron Parker Software Creations http://www.scbbs.com Self-Administration Web Site http://saw.scbbs.com SDSS Subscription Mgmt Service http://sdss.scbbs.com Central Ave Dance Ensemble http://www.centralavedance.com R & B Salsa http://www.randbsalsa.com
HOWEVER, when I click on the "submit" button and save the new node, the file attachments do NOT appear. Can someone tell me what I'm missing here?
upload.module has the code you'll need to study--specifically, upload_nodeapi and upload_save. Note that saving file associations is limited by a permission. The key question to consider is, what does upload do with a *new* node? In this case, any files associated with a node are those that were just uploaded. // New file upload elseif (strpos($file->fid, 'upload') !== FALSE) { This won't help you, as your files array doesn't contain this marker. Consider instead: elseif ($node->old_vid && is_numeric($fid)) { You could consider tricking upload.module into doing the handling by setting an old_vid. Or else just write your own handling based on upload_save.
upload.module has the code you'll need to study--specifically, upload_nodeapi and upload_save.
Note also that when you delete the original node, the original files attached to the cloned node will be deleted as well. There is work to assign files to user instead of nodes, and afaik this would solve the problem Philippe
Note that saving file associations is limited by a permission.
The key question to consider is, what does upload do with a *new* node? In this case, any files associated with a node are those that were just uploaded.
// New file upload elseif (strpos($file->fid, 'upload') !== FALSE) {
This won't help you, as your files array doesn't contain this marker.
Consider instead:
elseif ($node->old_vid && is_numeric($fid)) {
You could consider tricking upload.module into doing the handling by setting an old_vid. Or else just write your own handling based on upload_save.
participants (3)
-
Nedjo Rogers -
Philippe Jadin -
Ron Parker