Last active
January 22, 2017 22:15
-
-
Save himerus/d89b9d42a6d066b72a3f589930fa79d6 to your computer and use it in GitHub Desktop.
Uninstall a taxonomy vocabulary programmatically in Drupal 8.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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