You are here

function taxonomy_xml_import_form in Taxonomy import/export via XML 6

Same name and namespace in other branches
  1. 5.2 taxonomy_xml.module \taxonomy_xml_import_form()
  2. 5 taxonomy_xml.module \taxonomy_xml_import_form()
  3. 6.2 taxonomy_xml.module \taxonomy_xml_import_form()
  4. 7 taxonomy_xml.admin.inc \taxonomy_xml_import_form()

Builds the import form.

Form contains a selector to choose the import method used (upload, URL, Web Service). This selector should reveal or hide the appropriate secondary parameters. Uses JS and a bit of CSS to show/hide. With no JS, all options are shown but only the chosen one is used.

See also

taxonomy_xml_import_form_submit()

1 string reference to 'taxonomy_xml_import_form'
taxonomy_xml_import in ./taxonomy_xml.module
Menu callback for the import page.

File

./taxonomy_xml.module, line 247
taxonomy_xml.module This module makes it possible to import and export taxonomies as XML documents.

Code

function taxonomy_xml_import_form($form_state) {
  drupal_add_js(drupal_get_path('module', 'taxonomy_xml') . '/taxonomy_xml.js');
  drupal_add_css(drupal_get_path('module', 'taxonomy_xml') . '/taxonomy_xml.css');
  $formats = taxonomy_xml_formats();
  $vocs[0] = t('[Determined by source file]');
  foreach (module_invoke('taxonomy', 'get_vocabularies') as $vid => $voc) {
    $vocs[$vid] = $voc->name;
  }
  $vocs[-1] = t('[Create new]');
  $form['vid'] = array(
    '#type' => 'select',
    '#title' => t('Target vocabulary'),
    '#default_value' => variable_get('taxonomy_xml_vid', 0),
    '#options' => $vocs,
    '#description' => t('The vocabulary into which terms should be loaded.'),
  );
  $form['data_source'] = array(
    '#type' => 'fieldset',
    #'#title' => t('Data Source'),
    '#attributes' => array(
      'id' => 'data_source',
    ),
  );
  $form['data_source']['source_selector'] = array(
    '#type' => 'select',
    '#title' => t('Data Source'),
    '#options' => array(
      'none' => t('CHOOSE'),
      'upload-file' => t('Upload File'),
      'url' => t('Web URL'),
      'service' => t('Web Service'),
    ),
    '#attributes' => array(
      'id' => 'source_selector',
    ),
    '#default_value' => variable_get('taxonomy_xml_source_selector', 'none'),
  );
  $form['data_source']['upload_file'] = array(
    '#type' => 'file',
    '#title' => t('File to import'),
    '#description' => t('Click "Browse..." to select a local document to upload.'),
  );
  $form['data_source']['url'] = array(
    '#type' => 'textfield',
    '#title' => t('URL to import from'),
    '#description' => t('Enter the URL of a file or web service containing a vocabulary definition.'),
    '#default_value' => variable_get('taxonomy_xml_url', ''),
  );
  $available_services = taxonomy_xml_lookup_services('lookup', 'options');
  $form['data_source']['service'] = array(
    '#type' => 'fieldset',
    '#attributes' => array(
      'id' => 'edit-service-wrapper',
    ),
    'service_id' => array(
      '#type' => 'select',
      '#title' => t('Taxonomy Server'),
      '#description' => t('
        Choose one of the available taxonomy server services.
        These preset services are defined in the taxonomy_xml module
        and may be extended by other contributed modules.
      '),
      '#default_value' => variable_get('taxonomy_xml_service_id', ''),
      '#options' => $available_services,
    ),
    'identifier' => array(
      '#type' => 'textfield',
      '#title' => t('Unique Identifier for this service'),
      '#description' => t('ID, GIUD, LSID, URI or other UID as required by this service.'),
      '#default_value' => variable_get('taxonomy_xml_identifier', ''),
    ),
  );
  $form['format'] = array(
    '#type' => 'select',
    '#title' => t('Format of file'),
    '#default_value' => variable_get('taxonomy_xml_format', 'xml_format'),
    '#options' => $formats,
  );
  $form['recurse_down'] = array(
    '#type' => 'checkbox',
    '#title' => t('Recurse down the taxonomy tree'),
    '#description' => t('
      Some taxonomy sources return references to further external URL
      sources (child terms).
      Tick this if those references are to be followed.
      <br/>The recursion may get intensive, although the tasks will be "batched".
      <br/>Note: You will <b>need</b> taxonomy_enhancer or something similar to be
      recording the external IDs or relationships cannot be maintained
      over batches.
    '),
    '#default_value' => variable_get('taxonomy_xml_recurse_down', TRUE),
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('advanced'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['advanced']['duplicate'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow duplicate terms'),
    '#description' => t('If you want to keep the same term in different positions in the vocabulary hierarchy, check this'),
    '#default_value' => variable_get('taxonomy_xml_duplicate', FALSE),
  );
  $form['advanced']['reuseids'] = array(
    '#type' => 'checkbox',
    '#title' => t('Re-use IDs'),
    '#description' => t('If the source data includes numeric IDs, try to use them as Drupal term IDs. This may have mixed results on sites that are not directly synched.'),
    '#default_value' => variable_get('taxonomy_xml_reuseids', FALSE),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
  );
  $form['#attributes'] = array(
    'enctype' => 'multipart/form-data',
  );
  return $form;
}