Is it possible to make a copy of a page??

Comments

nevets’s picture

What do you mean by page? Do you mean the whole page or just the contents (no navigation, no menues, etc). If just the contents are you looking to copy node page content (content based on story, page or other content you add with 'create content'), a list of content, or something else?

dudez12’s picture

What I mean is, create another node page that is identicle in Content.

nevets’s picture

The Edit as new module does this but it is not updated for 4.7 yet.

dudez12’s picture

Any help?

dudez12’s picture

It is very critical that I know how to do this as soon as possible. Can anybody please explain how to copy a content page?

bpapa’s picture

Couldn't you just copy all the content code to a new page? Or am I missing some nuance of your question?

dudez12’s picture

The node a need to copy is a 'webform'.

nevets’s picture

Here is a copy of a module I wrote sometime ago to clone a node and have updated for 4.7. Make a directory under modules called clone, and place the code below in a file called clone.module. Enable the module. If people have permission a new link will be added labeled clone. Click the link and the node will be copied and the user placed on the edit page for the copy.

<?php

/**
 * Implementation of hook_perm().
 */
function clone_perm() {
  return array('clone node');
}

/**
 * Implementation of hook_link().
 */
 
function clone_link($type, $node = NULL) {
	$links = array();
	
  if ($node != NULL) {
		$links[] = l(t('clone'), 'clone/'. $node->nid);
    return $links;
  }
}

function clone_menu($may_cache) {
  $items = array();

  if ($may_cache) {
    $items[] = array('path' => 'clone', 'title' => t('clone'),
      'callback' => 'clone_node',
      'access' => user_access('clone node'),
      "type" => MENU_CALLBACK);
  }
  
  return $items;
}

function clone_node($nid)
{
	global $user;
	
	$node = node_load($nid);
	
	$node->nid = NULL;
	$node->name = $user->name;
	$node->created = 0;
	
	node_save($node);
	
	drupal_goto('node/'. $node->nid . '/edit');
}
    
?>

dudez12’s picture

This is exactly what I needed!! THANK YOU!!

dudez12’s picture

Is there anyway to make the "Clone" link completely invisible to users who do not have pernission to use it?

nevets’s picture

This version will hide the link if they do not have permission

function clone_link($type, $node = NULL) {
	$links = array();
	
  if ($node != NULL) {
		if ( user_access('clone node') ) {
			$links[] = l(t('clone'), 'clone/'. $node->nid);
	    return $links;
		}
  }
}
bonobo’s picture

nevets -- this is some very useful code -- thanks for this.

Cheers,

Bill

-------
http://www.funnymonkey.com
Tools for Teachers

pwolanin’s picture

This is should be very useful for most content, but I'm not sure it will work with webform- has anyone tried it yet? I think webform creates new tables where each field has a new ID, so I'm wondering if the "cloned" webform will have new entries in that table, or still point to the original ones?

Also, is this module in the contrib download area? Seems like there could be a potential problem with the last command, if the user has the "clone" permission, but not permission to edit that node type?

---
Work: BioRAFT

pwolanin’s picture

to answer my own question, it seems to work OK with webform. The component ID (cid) values are the same in the database, but since the nid values are different the modules seems able to distinguish the data as belonging to different forms.

---
Work: BioRAFT

bpapa’s picture

***Nevermind, wouldn't have helped anyway***

Are you using some internal form generation utility/module?

I had some pre-existing forms from before I went to Drupal, and I can just cut and paste their code right into the content area for a regular old page/node and they still work fine (provided their cgi/php/pl file is still accessable and properly permissioned (sp?) :)

I haven't bothered using the integrated form modules or whatever cuz there is no way its going to be as good/useful as the solution I already use...

dudez12’s picture

I am using the webform module.

pwolanin’s picture

I re-worked the code above into an actual contributed module:

http://drupal.org/project/node_clone

Please test it out. The "clone" link now appears as a tab when viewing a page. Also, it now resets the path and menu settings for the copied node to avoid overwriting the alias or menu placment of the original node.

I don't have flexinode or CCK installed, so I don't know whether this will work correctly with those content types.

Also, right now there is no check that the user can auctally edit the node that they copy- in some cases this may be OK, but in others may cause problems.

---
Work: BioRAFT

rondev’s picture

I just tried this to translate my form.
But as you said the fields are the same in every nodes. Then translating the name of a field in one form change the name in all others.
You made good job but not what I would like to have. That's very common with CMS.
Ronan

pwolanin’s picture

I had wondered if there would be side efffects of having the same component IDs. I'm guessing this wold affect custom theming of forms as well.

I don't think there is an easy way around this without special casing webform in the code. Probably just have to generate now component IDs when the clone is generated. Not a hard task if it's important to you.

---
Work: BioRAFT

rondev’s picture

That is not so important for me. I think it would be quicker to make new form than to modify modules and test them.
I don't know how you could generate component IDs when the clone is generated. If you want to do a try, I just can be a beta tester. Sorry not to help more.
I'd rather prefer adding i18n to the name of the fields of the webfom. But that is another challenge.
Thanx.
Ronan

mb2’s picture

Is there anyway to not have the Cloned node get published before editing? It appears the cloned page gets published before editing, and ends up on the front page if the node type is set to be automatically promoted, leaving "Clone of ----" as the lead story. I could adjust the promotion setting, but manually promoting stuff kind of defeats the purpose of the module for me because I want to use it as a time saver.

pwolanin’s picture

but the design is intended to make a nearly exact copy (including flags). While it would be possible to introduce a variety of schemes to filter or alter the flags via a settings page, it's not a priority for me.

The module code is pretty modest, and not too hard to hack. If you want to submit a patch as a feature request, I'll look at it. Otherwise, you could describe exactly what you want and offer a bounty.

---
Work: BioRAFT

mb2’s picture

I guess its not worth it for me to invest any time or money in now, since this module is definitely more of a luxury rather than a necessity for me. Thank you though for the response and the module itself.

pwolanin’s picture

I added another feature to the module which may help your use case. For each node type, you can now decide whether to reset the publishing options to the default for that noed type when a clone is made. So, for example, if your defualt for story nodes is (unpublished, not promoted), and you clone a story on the front page the clone can get reset to (unpublished, not promoted).

---
Work: BioRAFT

drupaceous’s picture

One problem with this module is when cloning an image node. The cloned node does not require the same image to be uploaded again, so that's a good thing. That way a node can be translated into another language.

However, when the original node is deleted, the image file on the server gets deleted as well, therefore the cloned image node has no image anymore.

It actually should behave like hard linking on Unix. When a hard link is created and the linked file is deleted, the link still has all the data of the linked file. Only when all the links are deleted, then the file content on the hard disk gets deleted as well.

pwolanin’s picture

If you know how to do this, please submit a feature request and a patch.

---
Work: BioRAFT

pamphile’s picture

nice work !! :)

zaglick’s picture

This Module helped me out a great deal A+ work