Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

content_copy_import_form

Definition

content_copy_import_form(&$form_state, $type_name = '')
contributions/cck/modules/content_copy/content_copy.module, line 240

Description

A form to import formatted text created with export.

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'), ); }

Code

<?php
function content_copy_import_form(&$form_state, $type_name = '') {
  include_once('./'. drupal_get_path('module', 'content') .'/includes/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('Import'),
  );
  // 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;
}
?>