function hansel_tokens in Hansel breadcrumbs 8
Same name and namespace in other branches
- 7 hansel.module \hansel_tokens()
Implements of hook_tokens().
File
- ./
hansel.module, line 802 - Hansel module
Code
function hansel_tokens($type, $tokens, $data = array(), $options = array()) {
global $_hansel_test_path;
if (!in_array($type, array(
'node',
'taxonomy_term',
'user',
))) {
return array();
}
switch ($type) {
case 'node':
$object = $data['node'];
$_hansel_test_path = 'node/' . $object->nid;
$title = $object->title;
break;
case 'taxonomy':
$object = $data['taxonomy_term'];
$_hansel_test_path = 'taxonomy/term/' . $object->tid;
$title = $object->name;
break;
case 'user':
$object = $data['user'];
$_hansel_test_path = 'user/' . $object->uid;
$title = $object->name;
break;
default:
return array();
}
$path = hansel_get_breadcrumbs(FALSE, TRUE, TRUE, array(
'alias',
));
if (is_array($path)) {
$path = $path['breadcrumb'];
}
else {
$path = array();
}
$_hansel_test_path = NULL;
if (variable_get('hansel_remove_first_token_item', TRUE)) {
array_shift($path);
}
if (empty($path)) {
$path = array(
t('content'),
$title,
);
}
$path = array_map('strtolower', $path);
if (module_exists('pathauto')) {
module_load_include('inc', 'pathauto');
if (function_exists('pathauto_cleanstring')) {
$path = array_map('pathauto_cleanstring', $path);
}
}
$path = implode('/', $path);
$replacements = array();
foreach ($tokens as $name => $original) {
if ($name == 'hansel-path') {
$replacements[$original] = $path;
}
}
return $replacements;
}