You are here

function crumbs_get_breadcrumb_data in Crumbs, the Breadcrumbs suite 7

Same name and namespace in other branches
  1. 6.2 crumbs.module \crumbs_get_breadcrumb_data()
  2. 7.2 crumbs.module \crumbs_get_breadcrumb_data()

Returns the breadcrumb data for the current page.

Gets the menu trail for the current page, and then uses it to build the breadcrumb. Each link is themed separately, and then the links are passed to theme('breadcrumb'), which returns the final rendered breadcrumb.

Note: If the existing Drupal-provided breadcrumb is empty, then Crumbs makes no effort to calculate its own, since it means that a module has intentionally removed it.

Breadcrumbs with one item are also ignored, to prevent the breadcrumb from being shown on the frontpage.

Return value

An associative array with the following keys:

  • trail: An array containing the menu trail of the current page.
  • items: An array containing the built breadcrumb.
  • html: The rendered breadcrumb received from theme('breadcrumb').

or FALSE if the breadcrumb could not be determined.

2 calls to crumbs_get_breadcrumb_data()
crumbs_block_view in ./crumbs.module
Implements hook_block_view()
crumbs_preprocess_page in ./crumbs.module
Implements hook_preprocess_page().

File

./crumbs.module, line 193
Provides an API for building breadcrumbs.

Code

function crumbs_get_breadcrumb_data() {
  static $data;
  if (!isset($data)) {
    $existing_breadcrumb = drupal_get_breadcrumb();

    // If the existing breadcrumb is empty, that means a module has
    // intentionally removed it. Honor that, and stop here.
    if (empty($existing_breadcrumb)) {
      $data = FALSE;
      return $data;
    }
    $show_current_page = variable_get('crumbs_show_current_page', FALSE);
    $trail = crumbs_get_trail();
    if ($show_current_page) {

      // Do not show the breadcrumb if it contains only 1 item. This prevents
      // the breadcrumb from showing up on the frontpage.
      if (count($trail) == 1) {
        $data = FALSE;
        return $data;
      }
    }
    else {

      // The current page should not be shown, remove it from the trail so that
      // the plugins don't need to waste time loading its title.
      array_pop($trail);
    }
    $breadcrumb_items = crumbs_build_breadcrumb($trail);
    $router_item = crumbs_get_router_item($_GET['q']);

    // Allow modules to alter the breadcrumb, if possible, as that is much
    // faster than rebuilding an entirely new active trail.
    drupal_alter('menu_breadcrumb', $breadcrumb_items, $router_item);
    $links = array();
    $last_item = end($breadcrumb_items);
    foreach ($breadcrumb_items as $i => $item) {
      if ($show_current_page && $item == $last_item) {

        // The current page should be styled differently (no link).
        $links[$i] = theme('crumbs_breadcrumb_current_page', $item);
      }
      else {
        $links[$i] = theme('crumbs_breadcrumb_link', $item);
      }
    }
    $html = theme('breadcrumb', array(
      'breadcrumb' => $links,
      'crumbs_breadcrumb_items' => $breadcrumb_items,
      'crumbs_trail' => $trail,
    ));
    $data = array(
      'trail' => $trail,
      'items' => $breadcrumb_items,
      'html' => $html,
    );
  }
  return $data;
}