Skip to content

Instantly share code, notes, and snippets.

@ccamara
Last active December 18, 2015 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccamara/5848437 to your computer and use it in GitHub Desktop.
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
<?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