Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
}
Comments
Comment #1
hass CreditAttribution: hass commented+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.
Comment #2
Amir Simantov CreditAttribution: Amir Simantov commentedCould this code come in my template.php until module has this feature?
Comment #3
hass CreditAttribution: hass commentedNot 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.Comment #4
jenlampton@Amir Simantov
This code will not work in your template.php, you would need a custom module to implement.
I am adding the token support into the next release, so hold tight :-)
Jen
Comment #5
jenlamptonCommitted to dev branch. new release coming shortly.
Jen
Comment #7
A Romka CreditAttribution: A Romka commentedso this is not working is it?