taxonomy_save_vocabulary

Versions
4.6
taxonomy_save_vocabulary($edit)
4.7 – 6
taxonomy_save_vocabulary(&$edit)

▾ 7 functions call taxonomy_save_vocabulary()

forum_enable in modules/forum/forum.install
forum_update_6000 in modules/forum/forum.install
Create the forum vocabulary if does not exist. Assign the vocabulary a low weight so it will appear first in forum topic create and edit forms. Do not just call forum_enable() because in future versions it might do something different.
taxonomy_check_vocabulary_hierarchy in modules/taxonomy/taxonomy.module
Dynamically check and update the hierarachy flag of a vocabulary.
taxonomy_form_term_submit in modules/taxonomy/taxonomy.admin.inc
Submit handler to insert or update a term.
taxonomy_form_vocabulary_submit in modules/taxonomy/taxonomy.admin.inc
Accept the form submission for a vocabulary and save the results.
taxonomy_overview_terms_submit in modules/taxonomy/taxonomy.admin.inc
Submit handler for terms overview form.
taxonomy_overview_vocabularies_submit in modules/taxonomy/taxonomy.admin.inc
Submit handler for vocabularies overview. Updates changed vocabulary weights.

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;
}
?>

Use case

bricef - Fri, 2009-11-06 12:05

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);
?>

Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.