[drupal-devel] [feature] Add functionality to make a copy of a node

syscrusher drupal-devel at drupal.org
Sat Apr 30 03:35:04 UTC 2005

Issue status update for http://drupal.org/node/21632

 Project:      Drupal
 Version:      cvs
 Component:    node system
 Category:     feature requests
 Priority:     normal
 Assigned to:  puregin
 Reported by:  puregin
 Updated by:   syscrusher
 Status:       patch

Thanks, Djun, for the detailed reply. I understand better now.


Previous comments:

April 29, 2005 - 20:57 : puregin

Attachment: http://drupal.org/files/issues/node_copy_patch (4.06 KB)

The purpose of this patch is to enable a copy operation on nodes.
The semantics of this are: given a node, a copy is saved.  Only
the title is changed (and of course the node will have new nid).
Hence, for example, copies of book pages are siblings of the

  Q. Are there any situations where having a copy of a node
will mess up a compound/structure?  

  Q. Should anything else be modfied (created/changed dates, ...)?

  Could you please review carefully - I'm pretty new to this
code!  Please pay special attention to:

    - permission checks - I'm not clear on the semantics of these
    - generation of watchdog entries / messages

  The patch makes the following changes:

1. Adds a function node_copy(&$node), based on node_submit.  This
accepts a node or node array, and checks if the current user has view
permissions and create permissions.  If so, it creates a title

    "(Copy of node ".$node->nid.") ". $node->title

It then clears the node's nid, and submits to node_save(), which
creates a new node. Appropriate messages are generated to indicate
success or reasons for failure.

2. Adds an item to the $items[] array in node_menu after line 710 to
allow adding copying a node '$nid' by by "node/$nid/copy".  This tries
to follow the way "node/$nid/delete" is handled.

3. Adds an operation

    'copy'   =>    array(t('Copy the selected posts'), ''),

(at line 748) to the operations array in function node_admin_nodes()
to allow mass copying of nodes (a la mass deletion of nodes).
Implements this operation.

4. Adds a case in function node_page() to take care of the copy


April 29, 2005 - 21:32 : syscrusher

Just a question...

How does what you propose differ from the EditAsNew module?


Just curious.



April 29, 2005 - 22:25 : puregin

Hi Scott,

This implements copy at the level of nodes, which feels
right to me.  That EditAsNew exist illustrates the need
for this functionality.  To me, having to implement this
outside of node.module is awkward and leads to potential
problems with concurrency.

Putting this in node.module also enables mass copying
of nodes, which seems like a useful thing to be able to
do.  It also exposes copying in a more programmatic

Modules which would like to support making copies
could offer this to users by generating a link.
This is parallel to the 'Add child' link functionality
presented by the 4.6 version of book.module.

On the other hand, EditAsNew has some nice design
ideas also - being able to selectively copy fields
might be useful.  Some users might prefer to see
this operation expressed as a tab.  It seems like
it should be possible to simplify EditAsNew based
on a copy function in node.module.  

Regards, Djun

More information about the drupal-devel mailing list