function _i18n_book_navigation_block in Book translation 6.2
Same name and namespace in other branches
- 6 i18n_book_navigation.module \_i18n_book_navigation_block()
Creates the block navigation. Assembles the navigation for the "current" book outline and translates the links into the desired language.
Parameters
stdClass $tnode: The current node object.
Return value
array The block array
See also
book_block() for more information
1 call to _i18n_book_navigation_block()
- i18n_book_navigation_block in ./
i18n_book_navigation.module - Implementation of hook_block()
File
- ./
i18n_book_navigation.module, line 137 - Defines the i18n book navigation module. Contains all necessary data and hooks
Code
function _i18n_book_navigation_block($tnode) {
$block = array();
// Get the node in the original language
$node = i18n_book_navigation_get_original_node($tnode);
// If it's the same as the current language, use the default block to save time
if ($node->language == i18n_get_lang()) {
$block = book_block('view');
return $block;
}
if (!empty($node->book)) {
$current_bid = $node->book['bid'];
}
else {
$current_bid = 0;
}
if (variable_get('book_block_mode', 'all pages') == 'all pages') {
$book_menus = array();
foreach (i18n_book_navigation_get_books() as $bid => $book) {
$tree = array();
if ($bid == $current_bid) {
$tree = i18n_book_navigation($node);
}
else {
$book['in_active_trail'] = FALSE;
$tree[0]['link'] = $book;
$tree[0]['below'] = FALSE;
}
if ($bid == $current_bid) {
// Set the breadcrumb
i18n_book_navigation_set_breadcrumb($tnode, $tree);
}
// Render
$book_menus[$bid] = menu_tree_output($tree);
}
$block['subject'] = t("i18n Book navigation");
$block['content'] = theme('book_all_books_block', $book_menus);
}
elseif ($current_bid) {
// Only display this block when the user is browsing a book.
$title = db_result(db_query(db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.nid = %d'), array(
$node->book['bid'],
)));
// Only show the block if the user has view access for the top-level node.
if ($title) {
$tree = i18n_book_navigation($node);
if (count($tree)) {
// There should only be one element at the top level.
$data = array_shift($tree);
$block['subject'] = theme('book_title_link', $data['link']);
$block['content'] = $data['below'] ? menu_tree_output($data['below']) : '';
}
}
}
return $block;
}