You are here

function taxonomy_xml_import_form in Taxonomy import/export via XML 6.2

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 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 336
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[TAXONOMY_XML_DETERMINED_BY_SOURCE_FILE] = t('[Determined by source file]');
  foreach (taxonomy_get_vocabularies() as $vid => $voc) {
    $vocs[$vid] = $voc->name;
  }
  $vocs[TAXONOMY_XML_CREATE_NEW] = t('[Create new]');
  $form['vid'] = array(
    '#type' => 'select',
    '#title' => t('Target vocabulary'),
    '#default_value' => variable_get('taxonomy_xml_vid', TAXONOMY_XML_CREATE_NEW),
    '#options' => $vocs,
    '#description' => t('
      The vocabulary into which terms should be loaded.
      If you choose a pre-existing vocabulary,
      existing vocabulary settings (tags, node types etc) will NOT be modified.
      If it is to be created new, they <em>may</em> be retained.
      Internal vocabulary ID "vid" cannot be imported.
    '),
  );
  $form['data_source'] = array(
    '#type' => 'fieldset',
    #'#title' => t('Data Source'),
    '#id' => 'data_source',
    '#attributes' => array(
      'id' => 'data_source',
    ),
  );
  $form['data_source']['protocol'] = array(
    '#type' => 'select',
    '#title' => t('Data Source'),
    '#options' => array(
      'none' => t('CHOOSE'),
      'upload-file' => t('Upload File'),
      'url' => t('Web URL'),
      'filepath' => t('Local File'),
      'service' => t('Web Service'),
    ),
    '#attributes' => array(
      'id' => 'protocol',
    ),
    '#default_value' => variable_get('taxonomy_xml_protocol', 'none'),
  );
  $form['data_source']['upload_file'] = array(
    '#type' => 'file',
    '#title' => t('File to import'),
  );
  global $user;
  if ($user->uid != 1) {
    $form['data_source']['upload_file']['#description'] = t('Only [%allowed_extensions] files are allowed.', array(
      '%allowed_extensions' => TAXONOMY_XML_ALLOWED_UPLOAD_EXTENSIONS,
    ));
  }
  $form['data_source']['url'] = array(
    '#type' => 'textfield',
    '#size' => 128,
    '#title' => t('URL to import from'),
    '#description' => t('
      Enter the URL of a file or web service containing a vocabulary definition.
      <br/>eg <em>http://www.w3.org/TR/2003/PR-owl-guide-20031215/food</em>
      <br/>The URL will be fetched requesting a content-type rdf/xml if available,
      this means sometimes you can enter URLs that look like web pages
      but we will actually retrieve the raw data.
      (On well-behaved sources)
    '),
    '#default_value' => variable_get('taxonomy_xml_url', ''),
  );
  $form['data_source']['filepath'] = array(
    '#type' => 'textfield',
    '#size' => 128,
    '#title' => t('Local filepath'),
    '#description' => t('
      Enter the path of a file containing an appropriately formatted vocabulary.
      The path can either be relative to the files directory or to Drupal root.
      <br>Eg: <pre>!example</pre>
    ', array(
      '!example' => drupal_get_path('module', 'taxonomy_xml') . '/samples/sample-Dewey_System-100_terms.csv',
    )),
    '#default_value' => variable_get('taxonomy_xml_filepath', ''),
  );
  $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('Optional ID, GIUD, LSID, URI or other UID as (if) required by this service.'),
      '#default_value' => variable_get('taxonomy_xml_identifier', ''),
    ),
    'information' => array(
      '#type' => 'markup',
      '#value' => l('More info about remote taxonomy services', 'admin/content/taxonomy/import/services'),
    ),
  );
  $form['data_source']['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_guid, taxonomy_enhancer, rdf,
      or something similar to be recording the external GUIDs
      or relationships (heirarchy) cannot be maintained over batches.
    '),
    '#default_value' => variable_get('taxonomy_xml_recurse_down', TRUE),
  );

  // Add this as a requirement!
  if (!module_exists('taxonomy_guid')) {
    $form['recurse_down']['#default_value'] = FALSE;
    $form['recurse_down']['#disabled'] = TRUE;
    $form['recurse_down']['#description'] = '<p><strong>' . t('Enable taxonomy_guid before trying recursion.') . '</strong></p>' . $form['recurse_down']['#description'];
  }
  $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['advanced']['taxonomy_xml_watchdog_level'] = array(
    '#type' => 'select',
    '#title' => t('Debug Level'),
    '#description' => t('To assist development, taxonomy_xml has the ability to display parsing messages as they are logged.'),
    '#options' => taxonomy_xml_watchdog_levels(),
    '#default_value' => variable_get('taxonomy_xml_watchdog_level', WATCHDOG_NOTICE),
  );
  $form['advanced']['flush_cache_description'] = array(
    '#type' => 'markup',
    '#prefix' => '<p>',
    '#suffix' => '</p>',
    '#value' => t('When retrieving remote data, a local cache is kept of successful file downloads. These are not expected to change, but may get in the way during testing. Flush the cache to delete them <em>all</em>.'),
  );
  $form['advanced']['flush_cache'] = array(
    '#type' => 'submit',
    '#value' => t('Flush Cache'),
    '#submit' => array(
      'taxonomy_xml_flush_file_cache',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
  );
  $form['#attributes'] = array(
    'enctype' => 'multipart/form-data',
  );
  return $form;
}