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.
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
.
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?
Comment | File | Size | Author |
---|---|---|---|
#3 | cck_copy_drupal_goto.patch | 804 bytes | fago |
#2 | content_copy_import_drupal_goto.patch | 549 bytes | njivy |
Comments
Comment #1
ac4lt CreditAttribution: ac4lt commentedI'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.
Comment #2
njivy CreditAttribution: njivy commentedcontent_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.
Comment #3
fagoform 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.
Comment #4
njivy CreditAttribution: njivy commentedTested with Drupal 5.1 and patched content_copy.module v1.4:
Comment #5
yched CreditAttribution: yched commentedFinally committed - sorry for the delay...
Comment #6
(not verified) CreditAttribution: commentedComment #7
liquidcms CreditAttribution: liquidcms commentedIs 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.
Comment #8
liquidcms CreditAttribution: liquidcms commentedand, in case anyone else stumbled upon this - i'll post my own answer: