You are here

function i18n_book_navigation_set_breadcrumb in Book translation 7.2

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

Set 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()

1 call to i18n_book_navigation_set_breadcrumb()
i18n_book_navigation_node_view in ./i18n_book_navigation.module
Implements hook_node_view().

File

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

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);
}