taxonomy_save_vocabulary

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

▾ 2 functions call taxonomy_save_vocabulary()

taxonomy_admin in modules/taxonomy.module
Menu callback; dispatches to the proper taxonomy administration function.
_forum_get_vid in modules/forum.module
Returns the vocabulary id for forum navigation.

Code

modules/taxonomy.module, line 119

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