function google_admanager_add_term_attribute in DFP Small Business (Google Ad Manager) 6.2
Same name and namespace in other branches
- 6.3 google_admanager.module \google_admanager_add_term_attribute()
- 7.2 google_admanager.module \google_admanager_add_term_attribute()
Re-usable function for adding term attributes
1 call to google_admanager_add_term_attribute()
- google_admanager_nodeapi in ./
google_admanager.module - Implementation of hook_nodeapi()
File
- ./
google_admanager.module, line 372
Code
function google_admanager_add_term_attribute($term) {
// Static caches to avoid repeating work and tracking already added terms
static $vocab_cache = array(), $added_terms = array();
// If we've already added this term, go no futher...
if (isset($added_terms[$term->tid])) {
return;
}
// If we've not built the vocab attribute "key" yet, do so now.
if (!isset($vocab_cache[$term->vid])) {
// Get the vocabulary
$vocab = taxonomy_vocabulary_load($term->vid);
// Build a "source key". This will be in the form of "v-{vocab name}". It must fit withint 10 characters
$orig_key = $key = 'v-' . _google_admanager_clean_string($vocab->name, 8);
// The counter and while loop ensures our shortened vocab names do not overlap
$counter = 1;
while ($vid = array_search($key, $vocab_cache) && $vid != $term->vid) {
$key = drupal_substr($orig_key, 0, 9) . $counter++;
}
// Set the unique key in the vocab cache
$vocab_cache[$vocab->vid] = $key;
}
// Add the attribute
google_admanager_add_attribute($vocab_cache[$term->vid], $term->name);
// Mark as "added"
$added_terms[$term->tid] = TRUE;
}