Skip to content

Instantly share code, notes, and snippets.

@jpoesen
Created May 29, 2012 16:34
Show Gist options
  • Save jpoesen/2829428 to your computer and use it in GitHub Desktop.
Save jpoesen/2829428 to your computer and use it in GitHub Desktop.
Turner ads UPDATED UPDATE HOOKS
<?php
// this goes into turner_ads.install
function turner_ads_update_6000(){
$vocabulary = array(
'name' => t("Advert type"), //Human readable name of the vocabulary
'multiple' => 0, //set 1 to allow multiple selection
'required' => 0, //set 1 to make the terms mandatory to be selected
'hierarchy' => 0, //set 1 to allow and create hierarchy of the terms within the vocabulary
'relations' => 0, //set 1 to set and allow relation amongst multiple terms
'module' => 'turner_ads', //provide the module name in which the vocabulary is defined and which is calling this function
'nodes' => array('page' => 1), //set the node to which this vocabulary will be attached
'weight' => -9, //set the weight to display the vocabulary in the list
);
taxonomy_save_vocabulary($vocabulary);
}
/**
* Create terms "skyscraper" and "rectangle" in voc "Advert types"
*/
function turner_ads_update_6010(){
$vocab_object = _turner_ads_get_vocabulary_by_name("Advert type");
$advert_vid = $vocab_object->vid;
$term = array(
'vid' => $advert_vid, // Voacabulary ID
'name' => 'skyscraper', // Term Name
);
taxonomy_save_term($term);
$term = array(
'vid' => $advert_vid, // Voacabulary ID
'name' => 'rectangle', // Term Name
);
taxonomy_save_term($term);
}
/**
* helper function to get VID from voc name.
*/
function _turner_ads_get_vocabulary_by_name($vocabulary_name) {
$vocabs = taxonomy_get_vocabularies(NULL);
foreach ($vocabs as $vocab_object) {
if ($vocab_object->name == $vocabulary_name) {
return $vocab_object;
}
}
return NULL;
}
function turner_ads_update_6030(){
$vocabulary = array(
'name' => t("Advert type"), //Human readable name of the vocabulary
'multiple' => 0, //set 1 to allow multiple selection
'required' => 0, //set 1 to make the terms mandatory to be selected
'hierarchy' => 0, //set 1 to allow and create hierarchy of the terms within the vocabulary
'relations' => 0, //set 1 to set and allow relation amongst multiple terms
'module' => 'turner_ads', //provide the module name in which the vocabulary is defined and which is calling this function
'nodes' => array('ad' => 1), //set the node to which this vocabulary will be attached
'weight' => -9, //set the weight to display the vocabulary in the list
);
taxonomy_save_vocabulary($vocabulary);
}
/**
* update new voc, apply to ad content type.
*/
function turner_ads_update_6040(){
$vid = _turner_ads_get_vocabulary_by_name('Advert type');
$voc = array(
'vid' => $vid,
'name' => t("Advert type"),
'nodes' => array('ad' => 1),
);
}
/**
* update new voc, apply to ad content type.
*/
function turner_ads_update_6050(){
$vid = _turner_ads_get_vocabulary_by_name('Advert type');
$voc = array(
'vid' => $vid,
'name' => t("Advert type"),
'nodes' => array('ad' => 1),
);
taxonomy_save_vocabulary($voc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment