[development] clone a node

Bryan Ollendyke bto108 at psu.edu
Mon Jul 21 13:46:12 UTC 2008

There's a switch statement based ajax function in outline_designer (
http://drupal.org/project/outline_designer) called duplicate.  The best way
to clone a node is to load it with drupal node_load then clear out the nid.
Then call node_save and it'll look at the node, see that there isn't a nid
and assign it one.  The rest of the fields will be saved via the nodeapi
hooks.  The function you wrote before looks very similar to the one I used.


On Mon, Jul 21, 2008 at 7:44 AM, Lluís <enboig at gmail.com> wrote:

> I have developed a simple group system (similar to OG in some ways,
> very diferent in others) so I need a user beeing able to import nodes
> from other groups to his own.
> To do so I have created a form which loads all the nodes from other
> groups as checkboxes. The checked items will be cloned to his group.
> I haven't tried node_clone, but I think it is UI oriented; I just need
> to clone a node knowing its ID (all group permissions, etc... are
> rewritten using nodeapi of my custom node).
> On Mon, Jul 21, 2008 at 11:59 AM, Nathaniel Catchpole
> <catch56 at googlemail.com> wrote:
> > You could take a look at the node_clone module if you haven't already:
> > http://drupal.org/project/node_clone
> >
> > On Mon, Jul 21, 2008 at 10:55 AM, Lluís <enboig at gmail.com> wrote:
> >> I have developed a custom module with custom node types and I need to
> >> make users able to clone nodes; would this be a good way to do so?
> >>
> >>      $clone=node_load($value);
> >>      $clone->is_new = true;
> >>      $clone->uid = $user->uid;
> >>      unset($clone->nid);
> >>      unset($clone->vid);
> >>      node_save($clone);
> >>
> >>
> >> --
> >
> --
> *La vida és com una moneda, la pots gastar en el que vulguis però
> només una vegada.
> *La felicitat ha de ser compatible, compartible i cooperativa.
> *Envellim quan els records superen les il·lusions.
> *Als llocs desconeguts només s'hi arriba per camins desconeguts.
> *Abans d'imprimir aquest missatge, pensa en el medi ambient.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080721/00906dcc/attachment.htm 

More information about the development mailing list