How to change a node's type?

Hide your eyes, conservatives: it's a node-change operation, the shocking switch from Blog Entry to Page, or Story to Review, whatever your desires demand. Call it a miracle or call it a travesty, modern Drupal science makes it possible... and seductively easy.

Question answer

I'll answer this question as quickly as I ask it – because I just tested it out while moving Drupally questions of various breed into a single node type on this site, the node type called "Drupal Questions" I created for my Question Bank. (It's a nice CCK-created node type with fields for the question, for the answer if available, and for a related URL.)

I had an old blog entry on a certain Drupal puzzle, and thought that node should be reworked into a Drupal Question. I was prepared to simply copy its content into a brand new node. But lo, that blog entry had a couple of comments, and I'd hate to lose those. How would I also move the comments from the old node to the new node I'd be creating? I dunno.

Hmm, a better idea: instead of making a new node, how about transforming the old blog entry node into a new type? I seemed to recall a module claiming that transfigurational wherewithal...

And here it is: Nodetype. http://drupal.org/project/nodetype

I downloaded the module and, before touching anything else, backed up my site database! That done, I installed Nodetype. It offers no admin options, and only shows up when you edit a node: you see a simple drop-down list of node types into which you can change the current node (complete with nice warning to only change the node type if you "know what you are doing"!)

In my case, I selected my custom node type "Drupal Questions" from the list. Doing a Preview of the node showed no changes, but hitting Submit put the change into effect. It worked great, and – the thing I was most hoping for – left the node's comments attached and intact. Nodetype, you swinging switch-hitter, you're all right by me!

You can see my results here: http://www.drupalace.com/blog_entry_trick_bin_hiding_node_title_2007_07_...

That node was a Blog Entry but is no longer; only its URL alias hints at its original configuration. (Kind of like the Adam's apple on "Lucy" in that Phuket night clu... no, the Ace is speaking too much here. Full stop.)

Now, I haven't used Nodetype enough to give out any handy tips, but the following safety procedures would seem wise:

1) Back up your database before dabbling in node DNA like this.

2) Your target node type may have different fields from your original node type, and I would imagine that data gets lost when a field gets dropped. Copy all major text field data from your original node before changing its type, to avoid loss.

3) Experiment first with a dummy node, if you really want to be safe before operating on the real thing.

 

If you've ever agonized over what node type to use for some piece of content, worried about getting "stuck with" the wrong decision, you can relax a bit with Nodetype in your arsenal. Bring out the tranny in your nodes! Good stuff.

Average: 4 (3 votes)

Trackback URL for this post:

http://www.drupalace.com/trackback/69

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may quote other posts using [quote] tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options