You are here

function i18n_book_navigation in Book translation 7.2

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

Get the translated menu tree for the original node.

Parameters

object $node: The node in the original language, that is part of the book outline.

array $config: (optional) Only used in context of the Menu Block module implementation. This array contains the information and settings passed to the hook_menu_block_tree_alter() hooks. Defaults to null.

Return value

array The translated menu tree, or an empty array

4 calls to i18n_book_navigation()
i18n_book_navigation_block_view in ./i18n_book_navigation.module
Implements hook_block_view().
i18n_book_navigation_menu_block_tree_alter in ./i18n_book_navigation.module
Implements hook_menu_block_tree_alter().
i18n_book_navigation_node_view in ./i18n_book_navigation.module
Implements hook_node_view().
i18n_book_navigation_preprocess_i18n_book_navigation in ./i18n_book_navigation.module
Implements hook_preprocess_i18n_book_navigation().
3 string references to 'i18n_book_navigation'
I18nBookNavigationPanelsTestCase::testPanelsIntegration in tests/i18n_book_navigation.test
Test panels integration.
I18nBookNavigationTestBase::setUp in tests/i18n_book_navigation.test
Sets up a Drupal site for running functional and integration tests.
i18n_book_nav.inc in plugins/content_types/i18n_book_nav.inc

File

./i18n_book_navigation.module, line 253
Defines the Book translation module.

Code

function i18n_book_navigation($node, $config = NULL) {
  $cache =& drupal_static(__FUNCTION__, array());
  if (!empty($node->book)) {

    // Disable the i18n node selection mode.
    $prev = i18n_select(FALSE);
  }
  else {

    // Nothing we can do.
    return array();
  }

  // If we have any configuration, we skip the cache.
  if (!empty($cache[$node->book['bid']]) && !isset($config)) {
    return $cache[$node->book['bid']];
  }

  // Get the original menu tree.
  if (!empty($config['expanded'])) {
    $tree = menu_tree_all_data($node->book['menu_name']);
  }
  else {
    $tree = menu_tree_all_data($node->book['menu_name'], $node->book);
  }

  // Translate the tree.
  $tree = i18n_book_navigation_translate_tree($tree);

  // Cleanup the "empty" leaves.
  $tree = i18n_book_navigation_cleanup($tree);
  if (!empty($node->book)) {

    // Revert the i18n node selection mode.
    i18n_select($prev);
  }
  $cache[$node->book['bid']] = $tree;
  return $tree;
}