What is the best/right way to create a CCK field?

Events happening in the community are now at Drupal community events on www.drupal.org.
drupalnesia's picture

I need to create a CCK field in my module. What is the best/right way?

From this link http://benbuckman.net/tech/10/01/drupal-automating-cck-field-creation-up... I got:

$form_state['values']['_add_new_field']['label'] = 'Name of New Field'; 
$form_state['values']['_add_new_field']['field_name'] = $new_field_name; 
$form_state['values']['_add_new_field']['type'] = 'computed'; 
$form_state['values']['_add_new_field']['widget_type'] = 'computed'; 
$form_state['values']['_add_new_field']['parent'] = 'group_some_group'; // put under fieldgroup (optional)  

// generate & submit the form
drupal_execute('content_field_overview_form', $form_state, $content_type);

Is above code the best/right way?

Comments

Are you trying to create a

Garrett Albright's picture

Are you trying to create a new field, or a new field instance? Your title says the former, but it looks like that page is talking about the latter.

Content Construction Kit (CCK)

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week