5

I'd like to create a content type. My problem is this content type will change frequently (every 6 months, I will add some fields and I will delete others).

How would you do it? I had thought several options:

1) Create a "version" field with a default value for every version I make. With the "hook_form_alter" I would hide or I would show fields according to the version.

2) Another option is to create a new content type for every version "contenttype_10", "contenttype_11", "contenttype_20",... Is there any module that makes possible create a new content type copying all the fields of a existing content type?

What do you think about it? What version is the best for you?

3
  • 2
    Please, describe why do you need to add fields on time basis and what those fields are supposed to do - there is a chance that cck isnt the best practice to solve your problem
    – Strae
    Commented Mar 24, 2011 at 15:54
  • 1
    Normally, a content type doesn't change so often; once you decided which fields it should include, they should not be continuously changed.
    – avpaderno
    Commented Mar 24, 2011 at 16:59
  • This content type is for requesting information to give or not a little amount of money to the applicant. Every 6 months I have to change the form to add or delete some fields. The form will have some fields for management (granting date, what department has made the decission,...). These last fields will be hidden fields for the applicant (using hook_form_alter).
    – user709
    Commented Mar 25, 2011 at 11:45

2 Answers 2

4

To be perfectly honest, if you're looking to actually keep the content you already have, this kind of meddling is best dealt with by simple augmentation and field visibility, in my opinion.

Having lots of content types is not really workable; there's a multitude of scenarios like search and views where pulling from multiple types is just not "working smart".

The way I see this is that, if I correctly understand it, CCK will basically create tables automatically for you for your fields; if you add fields, it adds more stuff to the schemas and tables. If you want to "remove" fields, CCK will scrap this data, ergo it will no longer exist.

The best way to go about this then, as I see it, is to periodically augment your one content type with the new fields, and simply hide the "old" fields with a field visibility module. If you're so inclined, you could do that programatically as you alluded to. Your old data is still available in the same type (and tables) in this manner.

For "versioning" output of your type, then yes, in theory you could add a version field to the type, but if you're periodically changing the fields (and consequently the node form) then it seems likely that you could just alter the output as easily. You would probably have to update various views and node templates in any case. Display suite module might help you accomplish that last bit more easily - UI to handle node display etc rather than keep getting your hands dirty in templates (useful if updating frequently?)

http://drupal.org/project/ds

http://grayside.org/field-permissions-plus

1
  • Thanks for you answer, NikLP. I think in the same way as you. I will construct an unique content type hiding or showing fields according to the version, operation (add/edit),..., through "hook_form_alter". I'll take a look at Display Suite module.
    – user709
    Commented Mar 25, 2011 at 11:48
5

The Features module is designed for this sort of database content to code version control. You could create your content type and export it as a Feature. That feature could then be version controlled like any other source code (using Git, SVN, etc).

If you just wanted to duplicate content types, the CCK module in Drupal 6 has a Content Copy sub-module that allows just that. In Drupal 7, I'm not sure if this is built into core. I would accomplish this task using Features.

1
  • Features module is great, but if I want to edit a node of this content type when I have already changed it I will see the info in a wrong form :(. On the other hand, I'm using Drupal 7 and I can't use Content Copy sub-module.
    – user709
    Commented Mar 24, 2011 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.