Skip to content

Instantly share code, notes, and snippets.

@himerus
Last active January 22, 2017 22:15
Show Gist options
  • Select an option

  • Save himerus/d89b9d42a6d066b72a3f589930fa79d6 to your computer and use it in GitHub Desktop.

Select an option

Save himerus/d89b9d42a6d066b72a3f589930fa79d6 to your computer and use it in GitHub Desktop.
Uninstall a taxonomy vocabulary programmatically in Drupal 8.
<?php
/**
* @file
* Contains various helper functions.
*/
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Helper function to remove a vocabulary and all associated terms.
*
* During uninstall of a module containing a vocabulary with terms, neither are
* removed automatically. Use this function to remove the vocabulary and terms
* with any associated vocabulary.
*
* @code
* function nodemaker_business_directory_uninstall() {
*
* // Uninstall the MY_CUSTOM_VOCAB taxonomy.
* _nodemaker_vocabulary_delete('MY_CUSTOM_VOCAB');
* }
* @endcode
*
* @param string $vid
* - Vocabulary id (system name) of the vocabulary to be removed.
*/
function _nodemaker_vocabulary_delete($vid) {
$vocab = Vocabulary::load($vid);
if ($vocab) {
$vocab->delete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment