0

Possible Duplicate:
Programmatically create Fields in Drupal 7

I want to to add a cck field to a content type Programatically in drupal 7.

Any one who have some idea about this?

  • What's your use case? Are you looking to add fields to existing content types that aren't going to change much (a typicaly use case), or are you writing a module that needs to dynamically add fields to various content types on a regular basis? – areynolds Sep 7 '11 at 8:33
  • I want to add cck field to existing content type like page or blog etc. – Ahmad Sep 7 '11 at 9:25
  • field_create_field() to create a field. field_create_instance() to attach a field to a entity type & bundle. I think there are duplicates for this already on StackExchange, so I'm not posting this as a reply. – Bojan Zivanovic Sep 7 '11 at 18:15
2

The main functions of the Content Creation Kit (CCK) have migrated into core in Drupal 7. Now every object used by Drupal (users, nodes, even taxonomy terms) are "fieldable entities." What does this mean? Simply that you can add fields to most objects in Drupal out of the box, no CCK required!

If you're building a module that alters pre-existing node types, you'll need to check out the Entity API. I'm not too familiar with it myself, however, it doesn't seem that hard to programmatically add fields. As Bojan Zivanovic mentioned, there are many other answers dealing with this on Drupal StackExchange, here are a few for you to peruse:

- Programmatically Creating Fields in Drupal 7

- Assign Fields Programmatically to Custom Node in Custom Module

If you're just adding fields to nodes for site building purposes, I'd just use the UI.

To do so...

  1. Go to the "Structure" menu.
  2. Select "Content Types."
  3. Click on "Manage fields" next to the content type you want to add fields to.

You should then be presented with an interface to add new fields to your content type, much like you did with CCK in Drupal 6.

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