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

ac4lt - February 2, 2007 - 23:16
Version:5.x-1.2» 5.x-1.3

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

njivy - February 5, 2007 - 18:02
Status:active» patch (code needs review)

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.

AttachmentSize
content_copy_import_drupal_goto.patch549 bytes

#3

fago - February 7, 2007 - 14:47
Category:feature request» bug report

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.

AttachmentSize
cck_copy_drupal_goto.patch804 bytes

#4

njivy - February 7, 2007 - 17:31
Status:patch (code needs review)» patch (reviewed & tested by the community)

Tested with Drupal 5.1 and patched content_copy.module v1.4:

  • Successfully imported content type via admin pages, with URL redirection
  • Successfully imported content type programmatically, without URL redirection

#5

yched - July 17, 2007 - 22:06
Status:patch (reviewed & tested by the community)» fixed

Finally committed - sorry for the delay...

#6

Anonymous - July 31, 2007 - 22:16
Status:fixed» closed

#7

liquidcms - May 11, 2008 - 20:22

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

liquidcms - May 11, 2008 - 20:38

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);
?>

 
 

Drupal is a registered trademark of Dries Buytaert.