You are here

function node_gallery_install_cck_type in Node Gallery 6.3

1 call to node_gallery_install_cck_type()
node_gallery_setup_content_type in ./node_gallery.install

File

./node_gallery.install, line 151
Install, update and uninstall functions for the node_gallery module.

Code

function node_gallery_install_cck_type($type = '<create>', $filename = '') {

  // Get the files content
  if (file_exists($filename)) {
    $macro = implode('', file($filename));
  }
  else {
    drupal_set_message(t('Unable to read cck file !file for import. Exiting.', array(
      '!file' => $filename,
    )), 'error');
    return;
  }
  if ($type != '<create>') {

    // add the imagefield for the image type.
    if ($type == NODE_GALLERY_DEFAULT_IMAGE_TYPE) {
      $content = array();
      eval($macro);
      $param = array(
        'type_name' => $type,
      );
      $param = array_merge($param, array_pop($content['fields']));
      if (!node_gallery_cck_field_exists($param)) {
        content_field_instance_create($param);
      }
    }
  }
  else {

    // Since we only need content copy once at install time, we cheat a bit here and include it
    // to take care of the case where CCK is installed and enabled, but content_copy isn't enabled
    require_once './' . drupal_get_path('module', 'content') . '/modules/content_copy/content_copy.module';

    // Build form state
    $form_state = array(
      'values' => array(
        'type_name' => $type,
        'macro' => $macro,
      ),
    );

    // form provided by content_copy.module
    drupal_execute('content_copy_import_form', $form_state);
    content_clear_type_cache();
  }
}