Last active
December 18, 2015 21:38
-
-
Save ccamara/5848437 to your computer and use it in GitHub Desktop.
Populates an existing vocabulary with terms when a module/feature is installed #drupal #taxonomy
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 | |
/** | |
* Implements hook_install(). | |
*/ | |
function yourmodule_install() { | |
// Populates 'name_of_vocabulary' vocabulary with taxonomy terms. | |
// Edit name_of_vocabulary with your desired vocabulary's machine name. | |
$vocabulary = taxonomy_vocabulary_machine_name_load('name_of_vocabulary'); | |
$terms = array(); | |
$terms[] = t('Taxonomy 1'); | |
$terms[] = t('Taxonomy 2'); | |
$terms[] = t('Taxonomy 3'); | |
foreach($terms as $name) { | |
$term = new stdClass(); | |
$term->vid = $vocabulary->vid; | |
$term->name = $name; | |
taxonomy_term_save($term); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment