Minimally overwriting a content type

published Jun 09, 2007, last modified Jun 09, 2007

If you want a new content type slightly different from an existing one, you might be able to use only GenericSetup to accomplish this. Update: 'diff -u' added; alternative way using the ZMI added; point to TemplateContentTypes by Rocky.

Sometimes you want to use an existing content type, but with slightly different settings. You might have a client who is technically happy to add a Document to a Folder, but who would rather add Eggs to Baskets. In other words: he wants to use the Document and Folder content types, but with a different name. Also, he might want to put only Eggs in his basket, and not Images and Files. You might be able to do this with zero lines of python code! The trick is that you can use GenericSetup to do your tweaking.
You make a new product: basket. You put that in your Products directory. You add an empty __init__.py. You add a profiles/default directory and register it in configure.zcml:
    xmlns="http://namespaces.zope.org/genericsetup"
i18n_domain="genericsetup">
name="default"
title="Basket profile"
description="Basket"
provides="Products.GenericSetup.interfaces.EXTENSION"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
/>

You add types.xml in profile/default:


After this, you copy CMFPlone/profiles/default/types/Folder.xml to profiles/default/types/Basket.xml. Then you change a few lines there . The diff (update: the 'diff -u' as rightfully requested by Reinout) is here:

 
-+ meta_type="Factory-based Type Information with dynamic views"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
- Folder
+ Basket
- name="description">A folder which can contain other items.
+ name="description">A Basket for Eggs
folder_icon.gif
- ATFolder
+ Basket
ATContentTypes
addATFolder
folder_listing
True
- False
-
+ True
+
+
+
False
folder_listing


-
-



Then you restart Zope, go to portal_Setup, in the Properties tab select your profile, in the Import tab select "Types Tool", press "Import selected steps" and you are done. Well, we have not looked at how to do this for normal Documents too, adding a content type Eggs based on them, but that should be the same technique, really.

Or as Wouter Vanden Hove says in a reaction: you can also go to portal_types, copy an existing content type (Document) to a new one (Egg), change Egg to your liking, go to portal_setup, export the Types Tool, unzip the resulting file in profiles/default and then remove all that is not an Egg or Basket from types.xml and remove all files other than Egg.xml and Basket.xml from the types directory. Those are a lot of steps, but it is probably takes longer to write this down than to actually do this. ;-)

If you really use this and submit this to a code repository like subversion, I recommend to first do a commit with the original Document.xml and Folder.xml (though renamed to Egg.xml and Document.xml) so you can more easily see what was actually changed.

By the way, I was trying this out and then I was triggered to write this blog entry by some commits I saw from Rocky in the collective: a new product TemplateContentTypes. That is a new product that he created on behalf of ServerZen Software and
Zest Software. It does something similar but also some more. I have not tried it yet. It probably contains some things that would be useful to add to the files above too, like profiles/default/factorytool.xml. Here is part of the README.txt of TemplateContentTypes:

A product designed to be used as the template or skeleton layout of a new set of types to completely replace ATContentTypes. Each custom type subclasses it's ATCT's equivalent.
Once the product has been installed inside a site, all standard actions that use/create/modify ATContentTypes based content will instead use the new template types.

Now create a Basket, add an Egg and enjoy!

Keywords
plone