function book_token_values in Token 6
Same name and namespace in other branches
- 5 token_node.inc \book_token_values()
Implements hook_token_values() on behalf of book.module.
File
- ./
token_node.inc, line 293 - Implementations of token module hooks for the core node and book modules.
Code
function book_token_values($type, $object = NULL, $options = array()) {
$values = array();
if ($type == 'node' && !empty($object)) {
$node = $object;
// Initialize tokens to empty strings.
$values['book'] = '';
$values['book-raw'] = '';
$values['book_id'] = '';
$values['bookpath'] = '';
$values['bookpath-raw'] = '';
if (!empty($node->book['mlid'])) {
// Exclude the current node's title from the book path trail (start with
// the book link's plid rather than mlid).
$parents = token_menu_link_get_parents_all($node->book['plid']);
$trail_raw = array();
foreach ($parents as $parent) {
$trail_raw[] = $parent['title'];
}
$trail = array_map('check_plain', $trail_raw);
// Load the root book page.
$root = token_menu_link_load($node->book['p1']);
$values['book'] = check_plain($root['title']);
$values['book-raw'] = $root['title'];
$values['book_id'] = $node->book['bid'];
$values['bookpath'] = !empty($options['pathauto']) ? $trail : implode('/', $trail);
$values['bookpath-raw'] = !empty($options['pathauto']) ? $trail_raw : implode('/', $trail_raw);
}
}
return $values;
}