I have ten content types that have tons of fields, including image fields with various image styles, etc. They are all mostly identical, except for a few fields. I would like to create one "master" content type and then copy it ten times. Then I could just change each of the ten copies to suite the different content types I need. This would save a TON of time. Keep in mind, this is all for the same Drupal installation. I'm not trying to copy a content type from one website to another. Is there a way to do this? I tried the Features module, and I did not have any luck, as all of my "features" were "overridden" and I gave up. I admit I did not try very hard, because I wanted to first make sure I wasn't going down the wrong path. Please help! Any assistance would be greatly appreciated. Thanks! - TheSasquatch

Comments

WorldFallz’s picture

afaik, features is the way this is supposed to be done (at least that's what is says about the d7 version of content_copy functionality on the cck project page).

I would probably create a feature for the content type you want to use as the master, then just so a search and replace on the code to rename it for new content types.

MrSasquatch’s picture

That sounds prone to unexpected glitches and other consequences. There should be a feature (core or community module) that allows for content types to be cloned with the click of a mouse. Any other ideas?

pixelsweatshop’s picture

IIRC there was a content type export/import in CCK in D6. Not sure if it's still there.

WorldFallz’s picture

nope-- that's the way i've always done it (though in d6 it was with the content_copy module).

MrSasquatch’s picture

Well, I appreciate your input, and if that's the best solution there is, I should try it. Can you please give me an example of the find-and-replace process? Like, if you could do a quick and simple example, and list the steps, that would be great. Thanks!!! - TheSasquatch

WorldFallz’s picture

It mostly depends on your desktop environment. Just create the feature for the content type you want to be the parent (including whatever other items you want included), open up the text editor of your choice and do a search and replace on the content type's name (ie search for change my_content_type_name and replace with my_content_type_new_name) in the feature's files. Most editors (like notepad++) allow you to be able to do that for multiple files at once.

kbell’s picture

cross-posting on this issue (with some more help) at http://drupal.org/node/1011620. Please see new module called bundle_copy, at http://drupal.org/project/bundle_copy.

Good luck,
-kbell

-Kelly Bell
twitter: @kelly, @gothamdrupal
http://gothamcitydrupal.com

vallab444’s picture

Hi, kbell: thanks for the contribution. tried it out, but found it rather confusing to use. can the UI be improved to resemble the Node Converter in Drupal 6.x?

-Vallab

liquidcms’s picture

yup, sadly this is another common use utility that has been lost in D7. bundle copy does replace some of this but at the moment it is only for export/import to another site; it has no ability to clone to existing site.

Unionhill’s picture

Tried Features, exported fine, but couldn't figure out how to turn the feature into a content type. Which file do I change the name in? Bundle copy didn't include the field dependencies I added. looks like field tools won't either. Thoughts? thanks

sprite’s picture

With the field tools module it is possible to copy content types and build new custom content types based on existing content types in seconds. I don't build a Drupal website without the "field tools" module, available for both D7 and D8. The node clone module serves a similar purpose, but for cloning a content, rather than content types.

https://www.drupal.org/project/field_tools

https://www.drupal.org/project/node_clone

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

Unionhill’s picture

will it include dependencies added conditional fields? Thanks

yousername’s picture

The Field Tools module allows you to choose any fields in a content type and export them into another existing content type, file, user and/or taxonomy vocabulary.

leex’s picture

I second this module, it was very very simple for me to duplicate all fields into an empty content type. Thanks for posting about it!

hunthunthunt’s picture

Agree, it was very easy to migrate existing fields to a new content type.

pdailor’s picture

Great module - thank you for pointing it out. I can't believe it has only 462 reported installs!

Nicholas Cook’s picture

agree, this module worked super fast for me, thanks for the recommend!

vonFrakas’s picture

Yikes! Almost spooky how easy that is.

Leo Pitt’s picture

field tools is quite fast but note that it doesn't copy across field groups (features does).

f4o’s picture

This module is just what I needed; to clone most of the fields to a fresh new bundle. Thanks a lot for this suggestion. To integrate field groups would be great. But hey, to make few clicks on top of this beautiful module is not a problem.

Happy Scientist’s picture

This is exactly what I was looking for! Thanks so much for pointing me to Field Tools.

carlodimartino’s picture

Yep. 'Tis a beauty, thanks!

Alain DG’s picture

Yep, thanks

vacho’s picture

I am solve my problen with
http://drupal.org/project/bundle_copy
generate a export code
edit the source code (very easy)
import the code

mikebrooks’s picture

As noted earlier in this thread, bundle_copy is intended for code export to a separate site.
If you don't edit the export code properly, you can foul up your site upon import. Only do this in a development environment.
@vacho - if you see my post, please reply to explain what parts of the code you edited. This will be helpful to others that attempt to use bundle_copy to clone a content type.

Thanks - Mike

2dareis2do’s picture

edit the source code (very easy)

Please can you elaborate please. I guess this depends how complicated your content type is right?

orangutangle’s picture

In a text editor:
1. Search and replace "old_content_type_machine_name" with "new_content_type_machine_name" (obviously use your own values here).
2. Update the following:

$data = array(
  'bundles' => array(
    'new_content_type_machine_name' => (object) array(
      'type' => 'new_content_type_machine_name',
      'name' => 'YOUR NEW CONTENT TYPE NAME',
      'base' => 'node_content',
      'module' => 'node',
      'description' => 'YOUR NEW CONTENT TYPE DESCRIPTION',

3. Save your changes, then paste into the Import tab.

csuggs4’s picture

I had a content type with 33 fields, and needed to create another content type that was nearly identical. The only difference was removing 6 fields. Bundle Copy worked like butter. I checked all boxes with one click, clicked the six I didn't need, copy/pasted the resulting export code into a text editor, find/replace the old type name with the new, and finally clicked Import under content types, pasted in the export code (with type names changed), and clicked submit.

Whoo, maybe kind of a run-on.

In any case, have to make sure the PHP Filter module is enabled and that you're a user capable of using that module, otherwise you won't find the import option.

bharata’s picture

That sounds pretty cool ,csuggs4 , but you are not cloning fields - you are "re-using" fields which is something very different. Cloning would create a new field + a new field instance while re-using only creates new instances. I would like to see a "clone field" option included in the "manage fields" UI.

orangutangle’s picture

Yes, exporting and reimporting using Bundle Copy clones the content type, but re-uses the fields. I think this is what most people want when they clone a content type, it certainly fits my use case.

campbdy’s picture

This is exactly what I would love too. Have read the suggested solutions in this thread, but a clone content type, like in views would be the ultimate for me.

Francewhoa’s picture

Loving back your Drupal community result in multiple benefits for you  
David Fiaty’s picture

Just a word to let you know I've created a module that clones a content type in one click without having to look at PHP code or replace fields:
https://www.drupal.org/sandbox/davidfiaty/2745827

It is a sandbox project at the moment but it's pretty stable and will soon be published as an official Drupal module.
Please let me know about your experience with Content Type Clone for Drupal!

David Fiaty’s picture

The official release of Content Type Clone for Drupal 7 is here!
https://www.drupal.org/project/content_type_clone
Hopefully we will have the Drupal 8 version soon.

CynthiaSeverson’s picture

Thanks David Fiaty for this information.

David Fiaty’s picture

The Content Type Clone module is now available on Drupal 8. Enjoy!