More complete breadcrumbs for Ubercart checkout

dylan

By default, Ubercart sets the breadcrumb on the checkout page to simply "Home", which I personally find a bit odd. Because it calls drupal_set_breadcrumb() late in the request cycle, it's not even possible to create menu links for use by the menu_breadcrumb or menutrails modules. Stranger still, the cart settings page offers a "Custom cart breadcrumb" text and URL option, but it's hard-coded to use a single link instead of a trail of links.

Here is a small snippet that will set the breadcrumbs to mimic the URL paths, for example:

Home › Cart › Checkout

/**
 * Implementation of hook_preprocess_page().
 */
function mymodule_preprocess_page(&$variables) {
  /*
   * This section sets the breadcrumb on the cart pages hierarchically
   * according to the path elements.  A preprocess function is
   * needed instead of drupal_set_breadcrumb() because Ubercart
   * aleady calls drupal_set_breadcrumb() with undesirable results,
   * which also thwarts the menutrails module.
   */
  $menu = menu_get_item();
  if (preg_match('/^cart($|\/)/', $menu['path'])) {
    $crumbs = array(l(t('Home'), '<front>'));
    $paths = array();
    foreach ($menu['map'] as $arg) {
      $paths[] = $arg;
      $crumbs[] = l(ucfirst($arg), implode('/', $paths));
    }
   $variables['breadcrumb'] = theme('breadcrumb', $crumbs);
  }
}

Comments

seems like a great idea, I'll

seems like a great idea, I'll try it out and see if it plays nicely with the checkout workflow

Thanks, I'll give it a whirl.

Thanks, I'll give it a whirl.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><blockquote>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options