You are here

function document_get_vocid in Document 8.x

Same name and namespace in other branches
  1. 6 document.inc \document_get_vocid()
  2. 7 document.inc \document_get_vocid()
4 calls to document_get_vocid()
document_add_type in ./document.callback.inc
document_get_types in ./document.inc
document_get_vocab in ./document.inc
document_install in ./document.install

File

./document.inc, line 42

Code

function document_get_vocid() {
  $vocid = variable_get('document_vocabulary', '');
  if (empty($vocid)) {

    // Check to see if document vocabulary exists
    $vocid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE module='document'")
      ->fetchField();
    if ($vocid) {

      // We found a vocabulary, so make sure it is associated with our content.
      $vocabulary = taxonomy_vocabulary_load($vocid);
      $vocabulary->nodes = array(
        'document' => 1,
      );
      $status = taxonomy_vocabulary_save($vocabulary);
    }
    else {

      // Didn't find one, so create vocabulary from scratch.
      $vocabulary = new stdClass();
      $vocabulary->name = 'Document types';
      $vocabulary->machine_name = 'document_types';
      $vocabulary->multiple = 0;
      $vocabulary->required = 1;
      $vocabulary->hierarchy = 2;
      $vocabulary->relations = 0;
      $vocabulary->module = 'document';
      $vocabulary->nodes = array(
        'document' => 1,
      );
      $status = taxonomy_vocabulary_save($vocabulary);
      $vocid = $vocabulary->vid;
    }
    variable_set('document_vocabulary', $vocid);
  }
  return $vocid;
}