How to create content types and or CCK fields in your module install/update code? I actually found this howto somewhere but I keep looking for it all the time. Here it is:
Step 1
Click the content type in UI and export it using Content Copy module into yourmodule.content.crud.inc file. Add <?php to the start of the file.
Step 2
Don't forget to add proper dependencies into it's .info file:
dependencies[] = content_copy
dependencies[] = any_other_cck_modules
Now put this into content of yourmodule_install():
include "yourmodule.content.robinhood_profile.inc";
$form_state = array();
$form = content_copy_import_form($form_state, $type_name);
$form_state['values']['type_name'] = $type_name ? $type_name : '
$form_state['values']['macro'] = '$content = '. var_export($content, 1) .';';
$form_state['values']['op'] = t('Import');
content_copy_import_form_submit($form, $form_state);
Voila! When you enable your module, your new content type will be created, including the CCK fields.
Jakub is owner and founder of Dynamite Heads. Jakub is a member of Drupal Security Team and supports Czech Drupal community at Drupal.cz









Uninstall
Hi Jakub,
Thanks for the post! A lot of people have been posting about what goes in the install but its hard to find documentation for what goes in the uninstall. How do you make sure the uninstall deletes the imported cck content type.
Thanks!
Poslat nový komentář