Fix for Import a content type from a file.

  1. <?php
  2. /**
  3.  * Import a content type from a file. Borrowed from cck_import_custom.module.
  4.  */
  5. function _mymodule_content_type_install($type, $create = TRUE) {
  6.   $export_data = file_get_contents(drupal_get_path('module', 'mymodule') . '/cck/' . $type . '.inc');
  7.  
  8.   // I like to store the exports with <?php so they are highlighted by text
  9.   // editors. Content Import doesn't expect files to contain <?php.
  10.   $export_data = preg_replace('/^<\?php/', '', $export_data);
  11.  
  12.   $form_state = array();
  13.   $create ? $form_state['values']['type_name'] = '<create>' : $form_state['values']['type_name'] = $type;
  14.   $form_state['values']['macro'] = $export_data;
  15.   drupal_execute('content_copy_import_form', $form_state);
  16. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.