diff --git a/includes/common.inc b/includes/common.inc index da8996a..37303b6 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -237,8 +237,15 @@ function drupal_get_profile() { * Sets the breadcrumb trail for the current page. * * @param $breadcrumb - * Array of links, starting with "home" and proceeding up to but not including + * Array of links (deprecated implementation) or of keyed arrays containing data + * for each breadcrumb item, + * starting with "home" and proceeding up to but not including * the current page. + * In the new implementation, each item contains: + * - title: The item's title (parent title); + * - url: The item's url (parent href); + * - options: Options for passing into the l() function. + * */ function drupal_set_breadcrumb($breadcrumb = NULL) { $stored_breadcrumb = &drupal_static(__FUNCTION__); @@ -246,17 +253,28 @@ function drupal_set_breadcrumb($breadcrumb = NULL) { if (isset($breadcrumb)) { $stored_breadcrumb = $breadcrumb; } + return $stored_breadcrumb; } /** * Gets the breadcrumb trail for the current page. + * + * @return + * Array of links (deprecated implementation) or of keyed arrays containing data + * for each breadcrumb item, + * starting with "home" and proceeding up to but not including + * the current page. + * In the new implementation, each item contains: + * - title: The item's title (parent title); + * - url: The item's url (parent href); + * - options: Options for passing into the l() function. */ function drupal_get_breadcrumb() { $breadcrumb = drupal_set_breadcrumb(); if (!isset($breadcrumb)) { - $breadcrumb = menu_get_active_breadcrumb(); + $breadcrumb = menu_get_active_breadcrumb_items(); } return $breadcrumb; @@ -6928,7 +6946,7 @@ function drupal_common_theme() { 'variables' => array('path' => NULL, 'width' => NULL, 'height' => NULL, 'alt' => '', 'title' => NULL, 'attributes' => array()), ), 'breadcrumb' => array( - 'variables' => array('breadcrumb' => NULL), + 'variables' => array('breadcrumb' => NULL, 'separator' => ' » '), ), 'help' => array( 'variables' => array(), diff --git a/includes/menu.inc b/includes/menu.inc index 4664d27..488ca63 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -2569,14 +2569,53 @@ function menu_get_active_trail() { /** * Gets the breadcrumb for the current page, as determined by the active trail. * - * @see menu_set_active_trail() + * @see menu_get_active_breadcrumb_items() + * + * @deprecated menu_get_active_breadcrumb_items is designed to replace it + * as it offers more flexibility for the theming. */ function menu_get_active_breadcrumb() { + $breadcrumb_items = menu_get_active_breadcrumb_items(); + + if (!$breadcrumb_items) { + return $breadcrumb_items; + } + $breadcrumb = array(); - // No breadcrumb for the front page. - if (drupal_is_front_page()) { - return $breadcrumb; + foreach ($breadcrumb_items as $breadcrumb_item) { + $breadcrumb[] = l( + $breadcrumb_item['title'], + $breadcrumb_item['url'], + $breadcrumb_item['options'] + ); + } + + return $breadcrumb; +} + +/** + * Gets data of each breadcrumb item for the current page. + * + * They are determined by the active trail. + * + * @return array + * Breadcrumb items' data for the current page as array of item information. + * each breadcrumb item is an associative array with the following + * components: + * - title: The item's title (parent title); + * - url: The item's url (parent href); + * - options: Options for passing into the l() function. + * + * @see menu_set_active_trail() + */ +function menu_get_active_breadcrumb_items() { + $breadcrumb_items = &drupal_static(__FUNCTION__); + + + // No breadcrumb for the front page or already set in the static variable. + if (drupal_is_front_page() || !empty($breadcrumb_items)) { + return $breadcrumb_items; } $item = menu_get_item(); @@ -2611,10 +2650,15 @@ function menu_get_active_breadcrumb() { } foreach ($active_trail as $parent) { - $breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']); + $breadcrumb_items[] = array( + 'title' => $parent['title'], + 'url' => $parent['href'], + 'options' => $parent['localized_options'], + ); } } - return $breadcrumb; + + return $breadcrumb_items; } /** diff --git a/includes/theme.inc b/includes/theme.inc index 9b606e9..de30860 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -1893,7 +1893,9 @@ function theme_image($variables) { * * @param $variables * An associative array containing: - * - breadcrumb: An array containing the breadcrumb links. + * - breadcrumb: An array containing either the breadcrumb + * links (deprecated), or an array of keyed array with + * breadcrumb item's data for building links. */ function theme_breadcrumb($variables) { $breadcrumb = $variables['breadcrumb']; @@ -1903,7 +1905,29 @@ function theme_breadcrumb($variables) { // screen-reader users. Make the heading invisible with .element-invisible. $output = '

' . t('You are here') . '

'; - $output .= ''; + $output .= ''; + return $output; } }