You are here

function i18n_book_navigation_set_breadcrumb in Book translation 6.2

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

Sets the breadcrumb. This is a port from menu_get_active_breadcrumb(). It will set the breadcrumb based on the current, translated tree.

Parameters

object $node: The node currently viewed (as in menu_get_item())

array $tree: The translated tree

See also

menu_get_active_breadcrumb()

2 calls to i18n_book_navigation_set_breadcrumb()
i18n_book_navigation_menu_block_tree_alter in ./i18n_book_navigation.module
Implementation of hook_menu_block_tree_alter() from the Menu Block module. A menu block configured for book navigations can now also be translated.
_i18n_book_navigation_block in ./i18n_book_navigation.module
Creates the block navigation. Assembles the navigation for the "current" book outline and translates the links into the desired language.

File

./i18n_book_navigation.module, line 41
Defines the i18n book navigation module. Contains all necessary data and hooks

Code

function i18n_book_navigation_set_breadcrumb($node, $tree) {
  $trail = array();
  $breadcrumb = array(
    l(t("Home"), '<front>'),
  );
  $href = 'node/' . $node->nid;
  list($key, $curr) = each($tree);
  while ($curr) {

    // Terminate the loop when we find the current path in the active trail.
    if ($curr['link']['href'] == $href) {
      $trail[] = $curr['link'];
      $curr = FALSE;
    }
    else {

      // Add the link if it's in the active trail, then move to the link below.
      if ($curr['link']['in_active_trail']) {
        $trail[] = $curr['link'];
        $tree = $curr['below'] ? $curr['below'] : array();
      }
      list($key, $curr) = each($tree);
    }
  }
  foreach ($trail as $element) {
    $breadcrumb[] = l($element['title'], $element['href'], $element['localized_options']);
  }

  // Remove the last element
  array_pop($breadcrumb);
  drupal_set_breadcrumb($breadcrumb);
}