You are here

function taxonomy_csv_import in Taxonomy CSV import/export 5

Same name and namespace in other branches
  1. 6.5 import/taxonomy_csv.import.api.inc \taxonomy_csv_import()
  2. 6.2 import/taxonomy_csv.import.api.inc \taxonomy_csv_import()
  3. 6.3 import/taxonomy_csv.import.api.inc \taxonomy_csv_import()
  4. 6.4 import/taxonomy_csv.import.api.inc \taxonomy_csv_import()
  5. 7.5 import/taxonomy_csv.import.api.inc \taxonomy_csv_import()
  6. 7.4 import/taxonomy_csv.import.api.inc \taxonomy_csv_import()

Generates the CSV import form.

1 string reference to 'taxonomy_csv_import'
taxonomy_csv_menu in ./taxonomy_csv.module
Implementation of hook_menu().

File

./taxonomy_csv.module, line 71
Quick import of lists of terms from a csv file.

Code

function taxonomy_csv_import() {
  $form = array(
    '#attributes' => array(
      'enctype' => 'multipart/form-data',
    ),
  );
  $form['source'] = array(
    '#type' => 'fieldset',
    '#title' => t('Source'),
  );
  $form['source']['upload'] = array(
    '#type' => 'file',
    '#title' => t('CSV file'),
  );
  if ($max_size = _taxonomy_csv_parse_size(ini_get('upload_max_filesize'))) {
    $form['source']['upload']['#description'] = t('Due to server restrictions, the maximum upload file size is !size. Files that exceed this size will be disregarded without notice.', array(
      '!size' => format_size($max_size),
    ));
  }
  $form['source']['delimiter'] = array(
    '#type' => 'select',
    '#title' => t('CSV file delimiter'),
    '#options' => array(
      TAXONOMY_CSV_COMMA => t('Comma – default'),
      TAXONOMY_CSV_SEMICOLON => t('Semicolon – Microsoft Excel'),
    ),
    '#description' => t('Choose the delimiter used in the CSV file you want to import.'),
  );
  $form['source']['columns'] = array(
    '#type' => 'radios',
    '#title' => t('Additional columns'),
    '#options' => array(
      TAXONOMY_CSV_IGNORE => t('Ignore'),
      TAXONOMY_CSV_FIELDS => t('Term description, term synonyms (may be empty)'),
      TAXONOMY_CSV_CHILDREN => t('Child term names (hierarchical vocabularies only)'),
      TAXONOMY_CSV_WEIGHTS => t('Term weights'),
    ),
    '#default_value' => TAXONOMY_CSV_IGNORE,
    '#description' => t('The first column is always imported as the term name. This option determines how additional columns will be imported. If your CSV file only contains one column, this option will be ignored.'),
  );
  $form['dest'] = array(
    '#type' => 'fieldset',
    '#title' => t('Destination'),
  );
  $form['dest']['vid'] = array(
    '#type' => 'select',
    '#title' => t('Vocabulary'),
    '#options' => array(),
    '#required' => TRUE,
    '#description' => t('The vocabulary you want to import the file into. You might want to !add-new-vocab.', array(
      '!add-new-vocab' => l(t('add a new vocabulary'), 'admin/content/taxonomy/add/vocabulary', array(), drupal_get_destination()),
    )),
  );
  $vocabularies = taxonomy_get_vocabularies();
  foreach ($vocabularies as $vid => $vocabulary) {
    $form['dest']['vid']['#options'][$vid] = $vocabulary->name;
  }
  $form['dest']['update'] = array(
    '#type' => 'radios',
    '#title' => t('Existing terms'),
    '#options' => array(
      FALSE => t('Ignore'),
      TRUE => t('Update if name matches'),
    ),
    '#default_value' => TRUE,
    '#description' => t('Whether existing terms with the same name should be re–created or updated.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
  );
  return $form;
}