Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In addition to the material in this handbook, developers may find the Content Construction Kit Group to be a useful source of information. That is an active group of people who develop and use CCK modules, and it's a good a place to read what others are doing, or post questions and announcements about CCK development. For a good introduction to the data model used by CCK, you may want to read the introduction to CCK article on the lullabot site.
Comments
Programmatic CCK content type creation
I found this too.
http://tinpixel.com/node/53
http://thedrupalblog.com/programmatically-create-any-node-type-using-dru...
Step 3: create a PHP function to hold your CCK definition
The template of the function will look like this, prior to pasting the contents of your copy buffer from above (containing the exported CCK content type definition code). We use a separate function just for the definition because it is must be updated with a new export from CCK if we decide to change or tweak our CCK content type later. It makes editing easier and less error prone.
function _modulename_cck_export() {
// paste code after this line.
// paste code before this line.
return $content;
}
Step 6: Write PHP code to actually create the content type
Write the install code to initiate creation of the new content type. This is where we make sure we have the necessary CCK pieces, populate a form using the now hard-coded CCK export, and then use drupal_execute() to submit the form to create the new content type. Here's an example:
function _example_install_cck_node() {
/* get the CCK node types to be created. This is where you load the
* file containing your function from above, if necessary, and then call
* that function.
*/
module_load_include('inc', 'modulename', 'modulename.ccknodedef');
$content = _modulename_cck_export(); // in modulename.ccknodedef.inc
// CCK content_copy.module may not be enabled, so make sure it is included
require_once './' . drupal_get_path('module', 'content')
. '/modules/content_copy/content_copy.module';
$form_state['values']['type_name'] = '';
$form_state['values']['macro'] = '$content = ' . var_export($content, TRUE) . ';';
// form provided by content_copy.module
drupal_execute('content_copy_import_form', $form_state);
content_clear_type_cache();
}
EDIT:
I'm happy to say the following code worked for me. ;-)
I'm also able to use node_import to import values into a newly created CCK node.
in the provider.install file
in the provider.module file
file structure
module/provider/provider.install
module/provider/provider.module
module/provider/cck_types/apples.txt
where apples.txt is a CCK export of the GUI.
ie
Enjoy.
This should be moved to a
This should be moved to a book sub-page...
This seems
This seems better:
http://drupal.org/node/350929
It would be great to have a step by step instruction for developers on installing content type export files with the modules.
My Drupal sites:
Programmatically alter field options
To alter the CCK field options on a particular content type programmatically, you can load the field, alter the values and then save it using
content_field_instance_update()
. This can be useful particularly when writing update hooks.Here's an example for adding an extra allowed value to a field: