function taxonomy_vocabulary_save

cis7 taxonomy.module taxonomy_vocabulary_save($vocabulary)
cle7 taxonomy.module taxonomy_vocabulary_save($vocabulary)
elmsmedia7 taxonomy.module taxonomy_vocabulary_save($vocabulary)
icor7 taxonomy.module taxonomy_vocabulary_save($vocabulary)
meedjum_blog7 taxonomy.module taxonomy_vocabulary_save($vocabulary)
mooc7 taxonomy.module taxonomy_vocabulary_save($vocabulary)

Saves a vocabulary.

Parameters

$vocabulary: A vocabulary object with the following properties:

  • vid: (optional) The ID of the vocabulary (omit if creating a new vocabulary; only use to update an existing vocabulary).
  • name: The human-readable name of the vocabulary.
  • machine_name: The machine name of the vocabulary.
  • description: (optional) The vocabulary's description.
  • hierarchy: The hierarchy level of the vocabulary.
  • module: (optional) The module altering the vocabulary.
  • weight: (optional) The weight of this vocabulary in relation to other vocabularies.
  • original: (optional) The original vocabulary object before any changes are applied.
  • old_machine_name: (optional) The original machine name of the vocabulary.

Return value

Status constant indicating whether the vocabulary was inserted (SAVED_NEW) or updated (SAVED_UPDATED).

10 calls to taxonomy_vocabulary_save()
defaultconfig_component_rebuild_vocabularies in sites/all/modules/ulmus/defaultconfig/defaultconfig.module
Provision vocabularies.
devel_generate_vocabs in sites/all/modules/ulmus/devel/devel_generate/devel_generate.inc
forum_enable in modules/forum/forum.install
Implements hook_enable().
standard_install in profiles/standard/standard.install
Implements hook_install().
taxonomy_check_vocabulary_hierarchy in modules/taxonomy/taxonomy.module
Checks and updates the hierarchy flag of a vocabulary.

... See full list

1 string reference to 'taxonomy_vocabulary_save'
_entity_info_add_metadata in sites/all/modules/ulmus/entity/entity.module
Adds metadata and callbacks for core entities to the entity info.

File

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

Code

function taxonomy_vocabulary_save($vocabulary) {
  // Prevent leading and trailing spaces in vocabulary names.
  if (!empty($vocabulary->name)) {
    $vocabulary->name = trim($vocabulary->name);
  }
  // Load the stored entity, if any.
  if (!empty($vocabulary->vid)) {
    if (!isset($vocabulary->original)) {
      $vocabulary->original = entity_load_unchanged('taxonomy_vocabulary', $vocabulary->vid);
    }
    // Make sure machine name changes are easily detected.
    // @todo: Remove in Drupal 8, as it is deprecated by directly reading from
    // $vocabulary->original.
    $vocabulary->old_machine_name = $vocabulary->original->machine_name;
  }

  if (!isset($vocabulary->module)) {
    $vocabulary->module = 'taxonomy';
  }

  module_invoke_all('taxonomy_vocabulary_presave', $vocabulary);
  module_invoke_all('entity_presave', $vocabulary, 'taxonomy_vocabulary');

  if (!empty($vocabulary->vid) && !empty($vocabulary->name)) {
    $status = drupal_write_record('taxonomy_vocabulary', $vocabulary, 'vid');
    taxonomy_vocabulary_static_reset(array($vocabulary->vid));
    if ($vocabulary->old_machine_name != $vocabulary->machine_name) {
      field_attach_rename_bundle('taxonomy_term', $vocabulary->old_machine_name, $vocabulary->machine_name);
    }
    module_invoke_all('taxonomy_vocabulary_update', $vocabulary);
    module_invoke_all('entity_update', $vocabulary, 'taxonomy_vocabulary');
  }
  elseif (empty($vocabulary->vid)) {
    $status = drupal_write_record('taxonomy_vocabulary', $vocabulary);
    taxonomy_vocabulary_static_reset();
    field_attach_create_bundle('taxonomy_term', $vocabulary->machine_name);
    module_invoke_all('taxonomy_vocabulary_insert', $vocabulary);
    module_invoke_all('entity_insert', $vocabulary, 'taxonomy_vocabulary');
  }

  unset($vocabulary->original);
  cache_clear_all();

  return $status;
}