function book_token_values in Token 5
Same name and namespace in other branches
- 6 token_node.inc \book_token_values()
Implementation of hook_token_values() for book nodes
File
- ./
token_node.inc, line 220 - Implementations of token module hooks for the core node and book modules.
Code
function book_token_values($type, $object = NULL, $options = array()) {
if ($type == 'node') {
$node = $object;
// Initialize some variables to empty.
$tokens['book'] = '';
$tokens['book-raw'] = '';
$tokens['book_id'] = '';
$tokens['bookpath'] = '';
$tokens['bookpath-raw'] = '';
if (!empty($node->parent)) {
$path = book_location($node);
$tokens['book'] = check_plain($path[0]->title);
$tokens['book-raw'] = $path[0]->title;
$tokens['book_id'] = $node->parent;
$bookhierarchy = book_location($node);
$bookpath = '';
$bookpath_raw = '';
foreach ($bookhierarchy as $bookelement) {
if ($bookpath == '') {
$bookpath = check_plain($bookelement->title);
$bookpath_raw = $bookelement->title;
}
else {
$bookpath = $bookpath . '/' . check_plain($bookelement->title);
$bookpath_raw = $bookpath_raw . '/' . $bookelement->title;
}
}
$tokens['bookpath'] = $bookpath;
$tokens['bookpath-raw'] = $bookpath_raw;
}
return $tokens;
}
}