Same name and namespace in other branches
  1. 4.7.x modules/taxonomy.module \taxonomy_save_vocabulary()
  2. 5.x modules/taxonomy/taxonomy.module \taxonomy_save_vocabulary()
  3. 6.x modules/taxonomy/taxonomy.module \taxonomy_save_vocabulary()
1 call to taxonomy_save_vocabulary()
_forum_get_vid in modules/forum.module
Returns the vocabulary id for forum navigation.

File

modules/taxonomy.module, line 119
Enables the organization of content into categories.

Code

function taxonomy_save_vocabulary($edit) {
  $edit['nodes'] = $edit['nodes'] ? $edit['nodes'] : array();
  $edit['weight'] = $edit['weight'] ? $edit['weight'] : 0;
  $data = array(
    'name' => $edit['name'],
    'description' => $edit['description'],
    'help' => $edit['help'],
    'multiple' => $edit['multiple'],
    'required' => $edit['required'],
    'hierarchy' => $edit['hierarchy'],
    'relations' => $edit['relations'],
    'weight' => $edit['weight'],
    'module' => isset($edit['module']) ? $edit['module'] : 'taxonomy',
  );
  if ($edit['vid'] && $edit['name']) {
    db_query('UPDATE {vocabulary} SET ' . _taxonomy_prepare_update($data) . ' WHERE vid = %d', $edit['vid']);
    db_query("DELETE FROM {vocabulary_node_types} WHERE vid = %d", $edit['vid']);
    foreach ($edit['nodes'] as $type) {
      db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
    }
    module_invoke_all('taxonomy', 'update', 'vocabulary', $edit);
    $message = t('Updated vocabulary %name.', array(
      '%name' => theme('placeholder', $edit['name']),
    ));
  }
  else {
    if ($edit['vid']) {
      $message = taxonomy_del_vocabulary($edit['vid']);
    }
    else {
      $data['vid'] = $edit['vid'] = db_next_id('{vocabulary}_vid');
      db_query('INSERT INTO {vocabulary} ' . _taxonomy_prepare_insert($data, 1) . ' VALUES ' . _taxonomy_prepare_insert($data, 2));
      foreach ($edit['nodes'] as $type) {
        db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
      }
      module_invoke_all('taxonomy', 'insert', 'vocabulary', $edit);
      $message = t('Created new vocabulary %name.', array(
        '%name' => theme('placeholder', $edit['name']),
      ));
    }
  }
  cache_clear_all();
  drupal_set_message($message);
  return $edit;
}