You are here

function taxonomy_xml_prepare_vocabulary in Taxonomy import/export via XML 7

Ensure a vocab will store our URI and extra values.

This adds a new 'guid' field and ressurects the missing 'synonym' field on taxonomy terms.

1 call to taxonomy_xml_prepare_vocabulary()
_taxonomy_xml_get_vocabulary_placeholder in ./taxonomy_xml.process.inc
Fetch the named vocab if it exists.

File

./taxonomy_xml.process.inc, line 56
The workhorse processes for importing taxonomies.

Code

function taxonomy_xml_prepare_vocabulary(&$vocabulary) {
  if (!$vocabulary->machine_name) {
    drupal_set_message("Cannot prepare a vocabulary with no machine name", 'error');
    return FALSE;
  }
  if (!field_info_field('field_guid')) {

    // Create the generic, uninstanced field definition.
    taxonomy_xml_create_guid_field();
  }
  if (!field_info_instance('taxonomy_term', 'field_guid', $vocabulary->machine_name)) {
    watchdog('taxonomy_xml', "Adding %field_type storage support to vocabulary %vocab_machinename.", array(
      '%field_type' => 'URI',
      '%vocab_machinename' => $vocabulary->machine_name,
    ), WATCHDOG_INFO);
    taxonomy_xml_create_guid_instance($vocabulary->machine_name);
  }
  if (!field_info_field('field_synonym')) {
    taxonomy_xml_create_synonym_field();
  }
  if (!field_info_instance('taxonomy_term', 'field_synonym', $vocabulary->machine_name)) {
    watchdog('taxonomy_xml', "Adding %field_type storage support to vocabulary %vocab_machinename.", array(
      '%field_type' => 'synonym',
      '%vocab_machinename' => $vocabulary->machine_name,
    ), WATCHDOG_INFO);
    taxonomy_xml_create_synonym_instance($vocabulary->machine_name);
  }
  watchdog('taxonomy_xml', "Prepared vocabulary %vocab_machinename with additional required fields.", array(
    '%vocab_machinename' => $vocabulary->machine_name,
  ), WATCHDOG_INFO);
  return TRUE;
}