By smanes on
I'm building a module which optionally supports CCK fields in the content_type it creates. Rather than instruct the user how to manually create these fields I'd like to be able to let him check a box on my module's admin submit form and create the CCK field for him. I'd use a snapshot of a CCK Export inside my code and send it to:
content_copy_import_form_submit($form, &$form_state)
Is there a better or less hacky way to do this?
Comments
With Drupal 6 CCK fields are
With Drupal 6 CCK fields are also suppose to be available as form elements (types), so I am wondering if it would not make more sense to store the information as part of your module and then when building the form add the elements using the form API. You can for example add a number field using the type 'number'.
I think I've got the answer
Or, at least, it works.
Content Types -> Export and select the prefab CCK field(s) you've constructed.
Copy the export dump to a file in your custom module's directory, i.e. personal_photo_type.cck.
In the hook_validate for your admin settings submission:
$modulepath = drupal_get_path ('module', 'YOUR_MODULE');
$cck_definition_file = $modulepath . '/personal_photo_type.cck';
$values['type_name'] = 'YOUR_CONTENT_TYPE';
$values['macro'] = file_get_contents($cck_definition_file);
$form_state = array('values' => $values);
drupal_set_message("Creating CCK field from $cck_definition_file");
drupal_execute("content_copy_import_form", $form_state);
content_clear_type_cache();