You are here

function _taxonomy_xml_get_vocabulary_placeholder in Taxonomy import/export via XML 5

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

Either fetch the named vocab if it exists, or create and return a useful placeholder.

Return value

the new vocab object.

3 calls to _taxonomy_xml_get_vocabulary_placeholder()
taxonomy_xml_absorb_vocabulary_definitions in ./taxonomy_xml.module
Use the vocabs defined as resources in the input to find or create vocabulary definitions.
taxonomy_xml_invoke_import in ./taxonomy_xml.module
Do the actual importing from the given string, pased on the parameters passed from the form.
taxonomy_xml_xml_parse in ./xml_format.inc
Initiate the parser on the custom XML schema.

File

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

Code

function _taxonomy_xml_get_vocabulary_placeholder($name) {
  if ($vocabulary = taxonomy_xml_get_vocabulary_by_name($name)) {

    // The node type array for a vocab has the type name as the key and the value set to 1
    // so we have to slightly modify the array or it will save wrong later
    $node_types = explode(',', $vocabulary->nodes);
    $vocabulary->nodes = array();
    foreach ($node_types as $type) {
      $vocabulary->nodes[$type] = 1;
    }
    return $vocabulary;
  }

  // Create new vocab
  $vocabulary = array(
    'name' => $name,
    'relations' => TRUE,
    'hierarchy' => 2,
  );
  module_invoke('taxonomy', 'save_vocabulary', $vocabulary);

  // Need to retrieve it from DB again - the result isn't given back to us.
  $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE LOWER('%s') LIKE LOWER(name)", $vocabulary['name']));
  $vocabulary = taxonomy_vocabulary_load($vid);
  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' => $vid,
    '!vocablink' => url('admin/content/taxonomy/edit/vocabulary/' . $vid),
  )));
  return $vocabulary;
}