Hello all,

If I do this print theme('breadcrumb', array('breadcrumb'=>drupal_get_breadcrumb())); I can get the breadcrumb of the current page. Specifically, I'm doing this in a Display Suite Custom Field. See this issue #1287048: Make content selection with no configuration screen work on dynamic fields which seems like it's being worked on now.

But was wondering for future applications too, is there a way to get the Custom Breadcrumb of the current page similar to how the above theme() function works?

Thanks for reading,
-Tim

Comments

Anonymous’s picture

Priority: Normal » Major

*bump*

Myself and somebody at http://drupal.org/node/955352 needs this too.

Raising priority to major. Please don't hit me.

sokrplare’s picture

Using what you had did the trick for me, but that was inside region--content.tpl.php (an Omega template file).

$breadcrumb = theme('breadcrumb', array('breadcrumb' => drupal_get_breadcrumb()));
jaroslaw.kaminski’s picture

I don't know what I'm doing wrong.
I added DS Code Field:

<?php
print theme('breadcrumb', array('breadcrumb'=>drupal_get_breadcrumb())); 
?>

and added to my Layout in DS
and I'm only getting:
"Home"

of course node type in CB is configured http://i.imgur.com/O5ZMih.png

jaroslaw.kaminski’s picture

bump? :)

basvredeling’s picture

This snippet only works in the theme layer because the custom breadcrumbs assembly has finished. It does so incrementally I believe. And there is no 1 function to just retrieve the assembled breadcrumbs.

I see 3 possible solutions:

  1. this first is a solution whereby the custom breadcrumbs are reassembled by a helper function. This function retraces the steps of loading a page and getting all the relevant custom breadcrumb definitions. It's ugly but it should work.
  2. Perhaps calling drupal_get_breadcrumbs() from a module with a very high weight might help as well.
  3. Create a custom_breadcrumbs submodule via the custom_breadcrumbs API that has a higher weight than all other custom_breadcrumbs modules and which applies to all custom_breadcrumb definitions. This could perhaps retrieve the complete breadcrumbs because it'd be the last one to call drupal_set_breadcrumb().
basvredeling’s picture

I gave up on trying to get this to work. My specific problem will be fixed using a workaround by fetching menu items instead.
FYI: if you're trying to retrieve the breadcrumbs on a panel page (for instance a node panel) you can try hook_ctools_render_alter(). For views try hook_views_post_render().

In the below example I'm getting the parent breadcrumb. It's all pretty hacky / ugly code, but hey... if it helps you guys out...

/**
 * Implements hook_ctools_render_alter().
 */
function MYMODULE_ctools_render_alter($info, $page, $args, $contexts, $task, $subtask, $handler) {
  if ($page && $handler->name == 'node_view_panel_context') { // replace $handler->name with your own panel page context
    // fetch the rendered breadcrumbs 
    $breadcrumbs = drupal_get_breadcrumb();

    // retrieve the url of the parent breadcrumb
    array_pop($breadcrumbs);
    $url = MYMODULE_extract_href(end($breadcrumbs));

    // convert the url to a system path
    $path = str_replace(base_path(), '', $url);
    $system_path = drupal_get_normal_path($path);

    // do your stuff with the retrieved system path
  }
}

/**
 * extract the href from an <a> tag
 */
function MYMODULE_extract_href($link) {
  $xml = simplexml_load_string($link);
  $list = $xml->xpath("//a/@href");

  $paths = array();
  foreach($list as $item) {
    $item = parse_url($item);
    $paths[] = $item['path'];
  }

  return($paths);
}
lamp5’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Closing this because is outdated. Only 7.2 branch and greater are supported.