Provide token for taxonomy title - code
cerber0s - September 12, 2009 - 09:21
| Project: | Taxonomy Title |
| Version: | 6.x-1.1 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
This code provides a token for taxonomy titles, very useful when used with the page title module. Can be added to the bottom of taxonomy_title.module
/**
* Implementation of hook_token_values().
*/
function taxonomy_title_token_values($type, $object = NULL, $options = array()) {
$values = array();
switch ($type) {
case 'taxonomy':
$category = $object;
// use taxonomy title if it exists, else category name
if($token = check_plain(_taxonomy_title_get_title($category->tid))){
}
else {
$token = check_plain($category->name);
}
$values['vocab-title'] = $token;
break;
}
return $values;
}
/**
* Implementation of hook_token_list().
*/
function taxonomy_title_token_list($type = 'all') {
if ($type == 'taxonomy' || $type == 'all') {
$tokens['taxonomy']['vocab-title'] = t("The vocabulary title from module taxonomy title if entered, if taxonomy title not specified will be taxonomy name (same as [vocab]).");
return $tokens;
}
}
#1
+1, code looks only like a prove of concept. After my review patch #636776: Full module review findings got in - I may work on this.
#2
Could this code come in my template.php until module has this feature?
#3
Not sure if it works, but at least there are some naming bugs inside like
['vocab-title']. I believe it need to be named['term-title'], but this is also a bug in the modules field name, too. The field on the term edit page is "improper" named Taxonomy Title and should better be Term title.