[Drupal 8] How to Create Taxonomy Vocabulary with Module Dependencies Programmatically on Drupal 8
I want to programmatically create taxonomy vocabulary and it should be enabled and disabled while the module installs and uninstalls the process. So first of all I have created a YAML file based on the vocabulary name with necessary definitions.
The name of the YAML file should be the format
taxonomy.vocabulary.keywords.yml. Here 'keywords' is my 'vid'. To make it proper as specified while module installation and uninstall, I have added the dependency with 'enforced' property. Note that the YAML file should be stored in YOUR MODULE/config/install folder otherwise it will not work. The definitions that I have added in the file are as follows:
langcode: en status: true dependencies: enforced: module: - sample_module name: Keywords vid: keywords description: 'Stores the keywords for sample_module' hierarchy: 0 weight: 0
After YAML file creation I have uninstalled and installed 'sample_module', and it worked. Hope this helps in your coding. Please feel free to get in touch with us for any queries.