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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ac4lt’s picture

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.

njivy’s picture

Status: Active » Needs review
FileSize
549 bytes

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.

fago’s picture

Category: feature » bug
FileSize
804 bytes

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.

njivy’s picture

Status: Needs review » 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
yched’s picture

Status: Reviewed & tested by the community » Fixed

Finally committed - sorry for the delay...

Anonymous’s picture

Status: Fixed » Closed (fixed)
liquidcms’s picture

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.

liquidcms’s picture

and, in case anyone else stumbled upon this - i'll post my own answer:


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