Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Can this be used to clone content types on the same site? I tried it, doing a search & replace of the source content type. While it did create the new content type, nervous about it. Not sure if some of those references should have been changed.
Anybody done it? Know what to change and not to change?
Comment | File | Size | Author |
---|---|---|---|
#44 | bundle_copy-1589118-44.patch | 7.41 KB | Anonymous (not verified) |
#36 | bundle_copy-1589118-36.patch | 9.18 KB | grasmash |
#27 | bundle_copy-clone_tab-1589118-27.patch | 7.54 KB | tinker |
#27 | bundle_copy-clone_tab.png | 20.25 KB | tinker |
#21 | bundle_copy-1589118-21.patch | 16.9 KB | daffodilsoftware |
Comments
Comment #1
sjk413 CreditAttribution: sjk413 commentedI exported a content type, did a find replace... and then imported it. My database then became corrupt, and I had to restore the site from a back up. I think it should be doable, but be more careful than I was. It's not simply find replace.
Their are also lists for each field in the export, showing which content types they are used in. So you'll need to add on their I guess. Equally this change to the list might confuse other content types.
eg.
I just thought I'd give you my experience. It could be risky. Definitely back up your site and give it a try, but read the entire export carefully. I would not try this on live site given my experience.
Has anyone else had success with this?
Comment #2
greta_drupal CreditAttribution: greta_drupal commentedYes, the
bundles' => array(
code was of most concern. In my one attempt, I did not replace every instance for this reason. But, still not so sure what is safe to change. Really hate to take a chance. But, I have another 4 or so custom content types to create which share some 20 fields, plus additional fieldgroups -- not to mention several build modes (which sadly this module doesn't address).Comment #3
liquidcms CreditAttribution: liquidcms commentedi exported type Article and did these replaces:
article => junk
Article => Junk
and did the import.
seems to work fine.
likely not too hard to make a patch for this; might give it a shot.
Comment #4
greta_drupal CreditAttribution: greta_drupal commentedI have done this several times now, and everything seems okay. Basically:
Change here:
Don't change here (it will auto update with your new content type after save):
Change here, if using fieldsets:
Comment #5
swentel CreditAttribution: swentel commentedOk, let's call it fixed then.
Comment #6
liquidcms CreditAttribution: liquidcms commentedi think until the module supports this feature this should remain active; but changing to a feature request.
Comment #7
liquidcms CreditAttribution: liquidcms commentedand here is patch to add this feature.
i throw a validation error if a user enters a new name but is trying to import more than 1 bundle; i also attempt to fix names that are entered to align with std bundle naming practice.
also, in this patch i added weights to the menu items so they sit at the bottom of the Content Types menu rather than mixed in with the types.
please test.
Comment #8
liquidcms CreditAttribution: liquidcms commentedoops...
Comment #9
greta_drupal CreditAttribution: greta_drupal commentedWoo hoo! I'll give it a try and report back.
Comment #10
greta_drupal CreditAttribution: greta_drupal commentedI'm afraid it didn't seem to work at all.
Error:
I assume this still references "lodging" (the cloned content type) because the error caused the cloning to fail. If not, definitely need better confirmation of the new content type creation.
Given that the patch shows "instance" for field, is this patch not taking Fieldgroups into consideration? That is a big thing in my development - I use them extensively. Without this too, I'd not likely use the patch. But, look forward to the fieldgroup inclusion!
Comment #11
greta_drupal CreditAttribution: greta_drupal commentedReferenced code line 318 (in my case):
$bundle = current($data['bundles']);
Comment #12
liquidcms CreditAttribution: liquidcms commentedwas a pretty simple patch; basically just changes the bundle name where it shows up... worked fine in my tests but failed with field collections.. which i think possibly nothing to do with patch; likely just bundle copy not yet supporting collections (although thought i have tested that). did test with field groups... will try it out.
odd error though; basically saying you have no bundles.
Comment #13
liquidcms CreditAttribution: liquidcms commentedhmm.. nope.. my bad.. my test node had both field groups and collections and worked fine.
my cloned node structure looks like this: http://screencast.com/t/w626ZGs6z
Comment #14
liquidcms CreditAttribution: liquidcms commentedoh yes, this won't work.. lol.. not related to your error though i dont think; i can't do a simple replace as some of my field names include the name of the bundle type...
Comment #15
greta_drupal CreditAttribution: greta_drupal commentedYes, I was going to point that out. Did you see my post above, about what to change and not change?
Comment #16
liquidcms CreditAttribution: liquidcms commentedyes, saw what you posted. that won't be correct either; at least not as a string search/repalce. look at your section on fieldgroups (not fieldsets) and see all the places that could potentially have the name of your bundle in there...
Comment #17
liquidcms CreditAttribution: liquidcms commentedhmm.. well i tried just changing the name/type in $data['bundles'] and $data['fieldgroups'] and left instances and fields alone; but that doesn't work - i end up with a new type with all my groups but no fields.
so went back to simple string replace on the $data eval string but this time did only whole word matches
this should now fix the issue with fields having bundle name in them - for example... type = Event and a field field_eventinfo
i still get this for many of my imports though: http://drupal.org/node/1622868#comment-6128156 so can't test too well.
Comment #18
greta_drupal CreditAttribution: greta_drupal commentedYes, and I indicated that is a section to change.
Comment #19
daffodilsoftware CreditAttribution: daffodilsoftware commentedI Created a new patch to clone the content type.
please test.
Comment #20
liquidcms CreditAttribution: liquidcms commented@daffodil - will gladly test out your patch but even if it is functional it will be difficult to get committed as you do not adhere to drupal coding standards. please check this out: http://drupal.org/coding-standards
Comment #21
daffodilsoftware CreditAttribution: daffodilsoftware commented@liquidcms I read the coding standards and do my code according to the standards.I again create the patch.I also worked on the cloning of taxonomy,User,Field API fields and Field groups.
Comment #22
emilekott CreditAttribution: emilekott commentedUnfortunately the patch in #21 produces an error if trying to clone any field groups.
Comment #23
emilekott CreditAttribution: emilekott commentedI have just looked into this further and I can clone field_groups manually by giving them a new identifier. I didn't realise that field_groups couldn't be reused but that appears to be the case.
Comment #24
daffodilsoftware CreditAttribution: daffodilsoftware commentedI will test it on my end and I couldnot produce the case .so can you please provide some more details like the modules versions that you are using of cck and drupal or anything else you may think that will be the case.
Comment #25
daffodilsoftware CreditAttribution: daffodilsoftware commentedHi emilekott
as I mentioned earlier I need more details as I am not getting any error.Also mention the error that you are getting
Comment #26
eckersley CreditAttribution: eckersley commentedGreetings. I got this to work (cloning a content type within the same site to a new name) by changing first near the top:
to
and then simply copying and replacing the rest of the way down thus:
with
Unfortunately this does not carry over your field display customizations with Display Suite.
Comment #27
tinker CreditAttribution: tinker commentedI decided to take a different tack on this problem. Since we are copying on the same site we do not need all the export code generation, dependency checks, and import decoding that are required (and complicated) for copying between different sites. To do a clone all we need is the source bundle and the new bundle name.
I have created a simple clone tab visible on the content types page that does just that. I have used it to copy very complex bundles. Right now I have only tested with nodes but the submit code is very simple and should work with all entities. I have field groups working but have not implemented field collections.
I went through the core code to see where the names have to be changed and have made specific changes rather than blanket search and replace.
Apply patch to clean 7.x-1.x-dev not in combination with any other patches on this page.
Comment #28
tinker CreditAttribution: tinker commentedSorry should have marked this needing review.
Comment #29
julien.reulos CreditAttribution: julien.reulos commentedThanks for the patch, it's working perfectly!
As a side note, I have to say that a few days later, doing a "Run updates", Drupal showed up this:
Not sure if it's due to the module or my site. The Clone menu element is present in Structure > Content types and working as expected, though.
Comment #30
tinker CreditAttribution: tinker commentedHi Julien. You could try this edit in bundle_copy.module -> bundle_copy_menu() around line 91.
You probably have another module that alters bundle_copy_bundle_copy_info(). If this fixes it let me know and I will re-roll a full patch.
Comment #31
julien.reulos CreditAttribution: julien.reulos commentedYes, may be Administration Menu. So, I made the changes, ran update and no more errors. Thanks!
Comment #32
greta_drupal CreditAttribution: greta_drupal commentedLovely! Any chance that this can be committed to the module as an option? (I am not in need of it right now. But, will make a point to try to test it soon.)
Comment #33
daffodilsoftware CreditAttribution: daffodilsoftware commentedI have not a live site yet on which I could test this patch.So I will commit it if anyone of the community member changed its status to reviewed and tested by community.
Comment #34
greta_drupal CreditAttribution: greta_drupal commentedOkay, I will test it this week.
Comment #35
grasmash CreditAttribution: grasmash commentedThis patch works fine with change from #30, but I don't think that it has the best approach.
Ideally, you should reuse bundle_copy_export_submit() and bundle_copy_import_submit(). If they can't be reused exactly, then they should be broken into smaller functions that can be reused by the cloning callback. The current approach just isn't very DRY, and it doesn't utilize good encapsulation.
Comment #36
grasmash CreditAttribution: grasmash commentedUpdated patch. Added fix from #30. Added Display Suite and Flag integration to clone feature.
*Still not using best coding practices,* but it works.
Comment #37
andyingham CreditAttribution: andyingham commentedIs patch in #36 compatible with Bundle Copy 7.x-1.1? Many thanks.
Comment #38
grasmash CreditAttribution: grasmash commentedI rolled that patch against the current dev version, at the time.
Comment #39
basicmagic.net CreditAttribution: basicmagic.net commentedi am using this to clone content types' fields, on the same site- and its been working great:
http://drupal.org/project/field_tools
just fyi...
Comment #40
Anonymous (not verified) CreditAttribution: Anonymous commentedChange title
Comment #41
Anonymous (not verified) CreditAttribution: Anonymous commentedTaking this one for today :)
Comment #42
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #43
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #44
Anonymous (not verified) CreditAttribution: Anonymous commentedI have re rolled the patch at #36 and added the feature of cloning of taxonomy also.sorry I am late by one day.
Comment #45
dshields CreditAttribution: dshields commentedComment #46
juan_g CreditAttribution: juan_g commentedI've just tested Bundle copy 7.x-2.x-dev. The release notes say:
"Added the new feature Cloning content types on same site."
https://drupal.org/node/1863660
Indeed, the module adds a new "CLONE" tab (and also "EXPORT" and "IMPORT") to:
Administration > Structure > Content types
For example, I've tested adding a new "Subgroup" content type for Organic Groups, cloning the default "Group" content type. In the CLONE tab:
Source Bundle:
Group
New Bundle Name:
Subgroup
And click in "Clone".
Wonderful, the new content type was created, almost exactly like the original, excepting of course the name "Subgroup" and the machine name "subgroup".
Naturally, I added my planned change, in:
Administration > Structure > Content types > Subgroup > Edit > Organic Groups
checking "Group content", in addition to "Group", so that a new "Groups audience" field for parent group is created.
And changed the content type description to "Group within another group."
And that was all, excepting one very small glitch in:
Administration > Structure > Content types > Subgroup > Edit > Comment settings > Default comment setting for new content
The original was "Hidden" and the copy "Open". Just this one difference, very easy to correct.
All the rest of the content type, the many settings in Edit, Manage Fields, Manage Display, Comment Fields, Comment Display, Panelizer... everything was perfectly cloned.
Great work, and thank you very much!
Comment #47
juan_g CreditAttribution: juan_g commentedUpdating the version to 7.x-2.x-dev, according to the release notes on this feature.
Comment #48
colan@juan_g: Let's not worry about some of the missing settings, as there's a separate issue for that: #1972950: Many node type properties not copied.
If there's another positive review (hopefully by me, once I try it), I think we can RTBC this.
Comment #49
colanThe patch doesn't apply so it needs a re-roll.
Cloning node content types works without the patch. If you're simply cloning those, you can get by without it.