diff --git a/includes/common.inc b/includes/common.inc index da8996a..fcc5efb 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -6928,7 +6928,12 @@ function drupal_common_theme() { 'variables' => array('path' => NULL, 'width' => NULL, 'height' => NULL, 'alt' => '', 'title' => NULL, 'attributes' => array()), ), 'breadcrumb' => array( - 'variables' => array('breadcrumb' => NULL), + // The "breadcrumb" is the old implementation that is kept for ensuring + // the backward compatibility. + // The "breadcrumb_items" is the new implementation and allows + // preprocessing the breadcrumb items before generating the links used in + // the final display. + 'variables' => array('breadcrumb' => NULL, 'breadcrumb_items' => NULL, 'separator' => ' » '), ), 'help' => array( 'variables' => array(), diff --git a/includes/menu.inc b/includes/menu.inc index 4664d27..0ba55c0 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -2569,14 +2569,50 @@ 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() */ 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 an 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 +2647,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..df7add8 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -1893,19 +1893,51 @@ function theme_image($variables) { * * @param $variables * An associative array containing: - * - breadcrumb: An array containing the breadcrumb links. + * - breadcrumb (deprecated): An array containing the breadcrumb links. + * breadcrumb_items should be preferred in order to allow other modules, + * themes "preprocessing" items' data; + * - breadcrumb_items: An array containing the data allowing to create + * the different breadcrumb links: + * - title: The item's title; + * - url: The item's url; + * - options: Options for passing into a l() function. + * - separator: The separator to use between the breadcrumb items in the + * final display. + * + * @return string + * The HTML display of the trail. */ function theme_breadcrumb($variables) { - $breadcrumb = $variables['breadcrumb']; + if (empty($variables['breadcrumb']) && empty($variables['breadcrumb_items'])) { + return ''; + } - if (!empty($breadcrumb)) { - // Provide a navigational heading to give context for breadcrumb links to - // screen-reader users. Make the heading invisible with .element-invisible. - $output = '

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

'; + // Provide a navigational heading to give context for breadcrumb links to + // screen-reader users. Make the heading invisible with .element-invisible. + $output = '

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

'; + $output .= ''; + + return $output; } /** @@ -2695,7 +2727,7 @@ function template_process_page(&$variables) { // re-use the cache of an already rendered menu containing the active link // for the current page. // @see menu_tree_page_data() - $variables['breadcrumb'] = theme('breadcrumb', array('breadcrumb' => drupal_get_breadcrumb())); + $variables['breadcrumb'] = theme('breadcrumb', array('breadcrumb_items' => menu_get_active_breadcrumb_items())); } if (!isset($variables['title'])) { $variables['title'] = drupal_get_title();