Last active
August 29, 2015 14:15
-
-
Save Cezarion/41d9830ca86fc4ec6d9e to your computer and use it in GitHub Desktop.
This file contains 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 | |
define('VOCAB_MACHINE_NAME', 'verticals'); | |
function case_studies_install() { | |
_create_vocabulary(); | |
$terms = array( | |
array( | |
'en' => 'Advertisers', | |
'fr' => 'Annonceurs', | |
), | |
array( | |
'en' => 'Agencies', | |
'fr' => 'Agences', | |
), | |
array( | |
'en' => 'Automotive', | |
'fr' => 'Automobile', | |
), | |
array( | |
'en' => 'Resellers', | |
'fr' => 'Revendeurs', | |
), | |
); | |
$vid = taxonomy_vocabulary_machine_name_load(VOCAB_MACHINE_NAME)->vid; | |
_create_terms($terms, $vid); | |
} | |
/** | |
* Create a taxonomy and attach a field to it. | |
*/ | |
function _create_vocabulary() { | |
$t = get_t(); | |
$vocab = new stdClass(); | |
$vocab->name = $t('Verticals'); | |
$vocab->machine_name = VOCAB_MACHINE_NAME; | |
$vocab->description = $t('Description'); | |
$vocab->hierarchy = 0; | |
$vocab->module = 'case_studies'; | |
$vocab->weight = 1; | |
$vocab->i18n_mode = 1; | |
taxonomy_vocabulary_save($vocab); | |
} | |
function _create_terms($terms = array(), $vid = NULL) { | |
foreach ($terms as $term_to_create) { | |
$term = new stdClass(); | |
$term->name = $term_to_create['en']; | |
$term->vid = $vid; | |
$term->language = LANGUAGE_NONE; | |
taxonomy_term_save($term); | |
_create_term_translation($term, 'fr', $term_to_create['fr']); | |
} | |
} | |
function case_studies_uninstall() { | |
$vid = taxonomy_vocabulary_machine_name_load(VOCAB_MACHINE_NAME)->vid; | |
taxonomy_vocabulary_delete($vid); | |
} | |
/** | |
* Create or update a translation string for a taxonomy term. | |
* | |
* @param $term | |
* The term object with the tid set. | |
* @param $langcode | |
* The langcode for the translation. | |
* @param $translation | |
* The translation string. | |
*/ | |
function _create_term_translation($term, $langcode, $translation, $property = 'name') { | |
$context = array( | |
'term', | |
$term->tid, | |
$property, | |
); | |
$textgroup = 'taxonomy'; | |
i18n_string_textgroup($textgroup)->update_translation($context, $langcode, $translation); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment