Drupal: How to Create CCK-Field
You need to create CCK-field. For example you may need to create CCK-field from hook_update_N.
Solution:
Unlike other CCK versions, fields manipulating becomes easier in CCK version for Drupal 6.
- You need to create a field with the help of CCK user interface first.
- Then you should use var_export() PHP-function, to get a dump of node field in the form of array.
var_export(content_fields(‘field_ИМЯ_ПОЛЯ’, ‘ТИП_КОНТЕНТА’));
See API: http://drupalcontrib.org/api/function/content_fields
Yyou will get a large array. You can copy your code there and use it in the following way:
$field = array (
‘field_name’ => ‘field_translator_note’,
‘type_name’ => ‘feature’,
‘display_settings’ =>
array (
4 =>
array (
‘format’ => ‘hidden’,
),
2 =>
array (
‘format’ => ‘hidden’,
),
3 =>
array (
‘format’ => ‘hidden’,
),
‘label’ =>
array (
‘format’ => ‘hidden’,
),
‘teaser’ =>
array (
‘format’ => ‘hidden’,
),
‘full’ =>
array (
‘format’ => ‘hidden’,
),
),
‘widget_active’ => ‘1’,
‘type’ => ‘text’,
‘required’ => ‘0’,
‘multiple’ => ‘0’,
‘db_storage’ => ‘0’,
‘module’ => ‘text’,
‘active’ => ‘1’,
‘columns’ =>
array (
‘value’ =>
array (
‘type’ => ‘text’,
‘size’ => ‘big’,
‘not null’ => false,
‘sortable’ => true,
),
),
‘text_processing’ => ‘0’,
‘max_length’ => ”,
‘allowed_values’ => ”,
‘allowed_values_php’ => ”,
‘widget’ =>
array (
‘rows’ => ”,
‘default_value’ =>
array (
0 =>
array (
‘value’ => ”,
),
),
‘default_value_php’ => NULL,
‘label’ => ‘Translator\’s note’,
‘weight’ => NULL,
‘description’ => ”,
‘type’ => ‘text_textarea’,
‘module’ => ‘text’,
),
);
// Load CCK –file where content_field_instance_create() function is defined
module_load_include(‘inc’, ‘content’, ‘includes/content.crud’);
// Add a few content types to the field and use this loop:
foreach (array(‘TYPE1′, ‘TYPE2′, ‘TYPE3′, ‘TYPE4′) as $type) {
// … and change content type in the proper field.
$field[‘type_name’] = $type;
content_field_instance_create($field);
}