You are here

function content_copy_import_form in Content Construction Kit (CCK) 5

Same name and namespace in other branches
  1. 6.3 modules/content_copy/content_copy.module \content_copy_import_form()
  2. 6 modules/content_copy/content_copy.module \content_copy_import_form()
  3. 6.2 modules/content_copy/content_copy.module \content_copy_import_form()

A form to import formatted text created with export.

The macro can be filled from a file, if provided. Example:

The macro can be filled from a file, if provided. Provide a type_name to force the fields to be added to a specific type, or leave out type_name to create a new content type.

Example: // If Content Copy is enabled, offer an import link. if (module_exists('content_copy')) { $form['macro'] = array( '#type' => 'fieldset', '#title' => t('Create a content type'), '#description' => t('Follow this link to create automatically a content type and import preconfigured fields.'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['macro']['link'] = array( '#type' => 'markup', '#value' => l(t('import'), 'admin/content/types/import', array(), 'type_name=event&macro_file='. drupal_get_path('module', 'my_module') .'/my_content_type.txt'), ); }

1 string reference to 'content_copy_import_form'
content_copy_menu in ./content_copy.module
Implementation of hook_menu().

File

./content_copy.module, line 253
Adds capability to import/export cck field data definitions.

Code

function content_copy_import_form($type_name = '') {
  include_once './' . drupal_get_path('module', 'content') . '/content_admin.inc';
  include_once './' . drupal_get_path('module', 'node') . '/content_types.inc';
  $form['#prefix'] = t('This form will import field definitions exported from another content type or another database.<br/>Note that fields cannot be duplicated within the same content type, so imported fields will be added only if they do not already exist in the selected type.');
  $form['type_name'] = array(
    '#type' => 'select',
    '#options' => array(
      '<create>' => t('<Create>'),
    ) + node_get_types('names'),
    '#default_value' => $type_name,
    '#title' => t('Content type'),
    '#description' => t('Select the content type to import these fields into.<br/>Select &lt;Create&gt; to create a new content type to contain the fields.'),
  );
  $form['macro'] = array(
    '#type' => 'textarea',
    '#rows' => 40,
    '#title' => t('Import data'),
    '#required' => TRUE,
    '#description' => t('Paste the text created by a content export into this field.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  // Read in a file if there is one and set it as the default macro value.
  if (isset($_REQUEST['macro_file']) && ($file = file_get_contents($_REQUEST['macro_file']))) {
    $form['macro']['#default_value'] = $file;
    if (isset($_REQUEST['type_name'])) {
      $form['type_name']['#default_value'] = $_REQUEST['type_name'];
    }
    $form['#prefix'] .= '<p class="error">' . t('A file has been pre-loaded for import.') . '</p>';
  }
  return $form;
}