You are here

function _taxonomy_xml_get_vocabulary_placeholder in Taxonomy import/export via XML 7

Same name and namespace in other branches
  1. 5.2 taxonomy_xml.module \_taxonomy_xml_get_vocabulary_placeholder()
  2. 5 taxonomy_xml.module \_taxonomy_xml_get_vocabulary_placeholder()
  3. 6.2 taxonomy_xml.module \_taxonomy_xml_get_vocabulary_placeholder()
  4. 6 taxonomy_xml.module \_taxonomy_xml_get_vocabulary_placeholder()

Fetch the named vocab if it exists.

Create and return a useful placeholder if not.

Parameters

string $name: Vocab name

Return value

bool|object The new vocab object.

6 calls to _taxonomy_xml_get_vocabulary_placeholder()
taxonomy_xml_absorb_vocabulary_definitions in ./taxonomy_xml.process.inc
Create Vocabulary definitions.
taxonomy_xml_invoke_import in ./taxonomy_xml.module
Do the actual importing from the given string.
taxonomy_xml_mesh_parse in formats/mesh_format.inc
Reads a XML file and creates the term definitions found in it.
taxonomy_xml_setup_vocabulary_from_data in formats/xml_format.inc
The setting is to initialize a vocabulary from the given settings (an array of attributes).
taxonomy_xml_source_features_rebuild in ./taxonomy_xml.features.inc
Create/recreate the items based on the data array.

... See full list

File

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

Code

function _taxonomy_xml_get_vocabulary_placeholder($name) {
  if (empty($name)) {
    drupal_set_message("Cannot create a vocabulary with no name", 'error');
    return FALSE;
  }
  if (!($vocabulary = taxonomy_xml_get_vocabulary_by_name($name))) {

    // Create new vocab.
    $machine_name = substr(preg_replace('/[^a-z0-9]+/', '_', strtolower($name)), 0, 21);
    $vocabulary = (object) array(
      'name' => $name,
      'relations' => TRUE,
      'hierarchy' => 2,
      'machine_name' => $machine_name,
    );
    taxonomy_vocabulary_save($vocabulary);
    drupal_set_message(t('Created vocabulary #%vid: %vocabname to put these terms into. You probably want to <a href="!vocablink">go edit it now</a>.', array(
      '%vocabname' => $vocabulary->name,
      '%vid' => $vocabulary->vid,
      '!vocablink' => url(TAXONOMY_XML_ADMIN . '/' . $vocabulary->machine_name . '/edit'),
    )));
  }
  else {

    // A valid Vocab exists,
    // But still may need to add some fields...
  }

  // Ensure vocab will store our URI and extra values.
  if (!taxonomy_xml_prepare_vocabulary($vocabulary)) {
    drupal_set_message("Problem preparing vocabulary", 'error');

    // dpm($vocabulary);
  }

  // The $vocabulary object will now have a vid.
  return $vocabulary;
}