drupal_goto() in content_copy_import_form_submit()
njivy - February 2, 2007 - 03:47
| Project: | Content Construction Kit (CCK) |
| Version: | 5.x-1.3 |
| Component: | General |
| Category: | bug report |
| Priority: | normal |
| Assigned: | njivy |
| Status: | closed |
Description
I want to programmatically create content types in hook_install(). However, content_copy_import_form_submit() contains drupal_goto(), which breaks the process.
Here's some context near line 430 of content_copy.module.
<?php
if (!form_get_errors()) {
if (sizeof($imported_fields) > 0 || sizeof($imported_groups) > 0) {
drupal_goto('admin/content/types/'. $content_info['content types'][$type_name]['url_str'] .'/fields');
}
else {
drupal_goto('admin/content/types');
}
}
?>How can we avoid this when programmatically submitting this form?

#1
I'm trying to do a similar thing. Seems like if there was an api that bypassed the forms like:
content_copy_construct_type($macro)
then we could just pass the string in and the form version could in turn just call this new function. Then the form version can do the goto if it needs to but the new, lower level function would just make the new type.
#2
content_copy_import_form_submit()could detect the context by checking for $_POST['macro'].I don't see a way to restructure this function unless we create a new form ID, but that defeats the purpose of FAPI's programmatic interface.
#3
form submit handlers shouldn't use drupal_goto() but redirect with the help of the formapi.
So this would be a better fix, that would fix your problem too.
Please test.
#4
Tested with Drupal 5.1 and patched content_copy.module v1.4:
#5
Finally committed - sorry for the delay...
#6
#7
Is there a handbook page or something that explains how to actually do what the original poster wanted to do (but didn't post)?
I have an exported CCK type (content_copy.module) and want to import this with install of a module.
#8
and, in case anyone else stumbled upon this - i'll post my own answer:
<?php
function _create_content_type($cck_definition_file) {
include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc');
include_once('./'. drupal_get_path('module', 'content') .'/content_admin.inc');
$values = array();
$values['type_name'] = '<create>';
$values['macro'] = file_get_contents($cck_definition_file);
drupal_execute("content_copy_import_form", $values);
}
$file = "pathtoyourfile/yourexport.cck";
_create_content_type($file);
?>