taxonomy_save_vocabulary
- Versions
- 4.6
taxonomy_save_vocabulary($edit)- 4.7 – 6
taxonomy_save_vocabulary(&$edit)
Code
modules/taxonomy/taxonomy.module, line 196
<?php
function taxonomy_save_vocabulary(&$edit) {
$edit['nodes'] = empty($edit['nodes']) ? array() : $edit['nodes'];
if (!isset($edit['module'])) {
$edit['module'] = 'taxonomy';
}
if (!empty($edit['vid']) && !empty($edit['name'])) {
drupal_write_record('vocabulary', $edit, 'vid');
db_query("DELETE FROM {vocabulary_node_types} WHERE vid = %d", $edit['vid']);
foreach ($edit['nodes'] as $type => $selected) {
db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
}
module_invoke_all('taxonomy', 'update', 'vocabulary', $edit);
$status = SAVED_UPDATED;
}
else if (!empty($edit['vid'])) {
$status = taxonomy_del_vocabulary($edit['vid']);
}
else {
drupal_write_record('vocabulary', $edit);
foreach ($edit['nodes'] as $type => $selected) {
db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
}
module_invoke_all('taxonomy', 'insert', 'vocabulary', $edit);
$status = SAVED_NEW;
}
cache_clear_all();
return $status;
}
?>Login or register to post comments 
Use case
I just saw this in forum module and i think it could be an interesting way to explain how this function work :
<?php
$vocabulary = array(
'name' => t('Forums'),
'multiple' => 0,
'required' => 0,
'hierarchy' => 1,
'relations' => 0,
'module' => 'forum',
'weight' => -10,
'nodes' => array('forum' => 1),
);
taxonomy_save_vocabulary($vocabulary);
?>