You are here

function _i18n_book_navigation_block in Book translation 6

Same name and namespace in other branches
  1. 6.2 i18n_book_navigation.module \_i18n_book_navigation_block()

Creates the block array. Assembles the navigation for the "current" book outline and translates the links to the desired language.

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 99

Code

function _i18n_book_navigation_block($node) {
  global $language;
  $block = array();
  $book_menus = array();
  $pseudo_tree = array(
    0 => array(
      'below' => FALSE,
    ),
  );

  // Get the original node
  $node = _i18n_book_navigation_get_original_node($node);
  $block['subject'] = t('i18n Book navigation');
  foreach (_i18n_book_navigation_get_books() as $book_id => $book) {
    if ($book_id == $node->book['bid']) {
      $result = i18n_book_navigation_menu_all_data($node->book['menu_name']);

      // Get the entire tree
      $tree = menu_tree_data($result);

      // Create the tree with only the active trail expanded
      $menu_tree = _i18n_book_navigation_create_menu_tree($tree, $node->book['mlid']);

      // Output the menu
      $book_menus[$book_id] = menu_tree_output($menu_tree);
    }
    else {

      // Since we know we will only display a link to the top node, there
      // is no reason to run an additional menu tree query for each book.
      $book['in_active_trail'] = FALSE;
      $pseudo_tree[0]['link'] = $book;
      _i18n_book_navigation_translate($pseudo_tree[0]['link']);
      $book_menus[$book_id] = menu_tree_output($pseudo_tree);
    }
  }

  // Use the book module to theme the navigation
  $block['content'] = theme('book_all_books_block', $book_menus);
  return $block;
}