1.20.x taxonomy_vocabulary.class.inc TaxonomyVocabulary::save()

Saves a taxonomy vocabulary to configuration.

Return value

Either SAVED_NEW if the vocabulary was created, or SAVED_UPDATED if the: vocabulary was updated.

File

modules/taxonomy/taxonomy_vocabulary.class.inc, line 71

Class

TaxonomyVocabulary
Taxonomy vocabularies allow the grouping of taxonomy terms.

Code

function save() {
  module_invoke_all('taxonomy_vocabulary_presave', $this);

  $config = config('taxonomy.vocabulary.' . $this->machine_name);
  $is_new = $config->isNew();
  $config->set('name', $this->name);
  $config->set('machine_name', $this->machine_name);
  $config->set('description', $this->description);
  $config->set('hierarchy', $this->hierarchy);
  $config->set('language', $this->language);
  $config->set('weight', $this->weight);
  $config->save();

  if ($is_new) {
    $status = SAVED_NEW;
    module_invoke_all('taxonomy_vocabulary_insert', $this);
    field_attach_create_bundle('taxonomy_term', $this->machine_name);
  }
  else {
    $status = SAVED_UPDATED;
    module_invoke_all('taxonomy_vocabulary_update', $this);
  }

  backdrop_static_reset('taxonomy_vocabulary_load_multiple');
  return $status;
}