I am actually using Custom Breadcrumbs for configuring the breadcrumbs for various types of content. However I have a few generic content types that must have a different breadcrumb, depending on the value of a field (mainly based on taxonomy, but other values as well). I wanted to use Custom Breadcrumbs as well for showing up the specific breadcrumbs for those types, but obviously it is not possible "out of the box". Since I already had a small module for creating some tokens (used by the autopath for URL aliasing) I thought of adding two different tokens containing the list of titles and paths. Since the depth of the breadcrumb can vary for a specific node type (some are at second level, other at third and others at fourth level) so it is not possible to have a separate token for each title and list all tokens in the Custom Breadcrumb configuration page. So I directlly created the values of the tokens with the list of titles and paths, separated by \n. However they would show up as an single title, not splitting the different titles.
After looking up the code I found out the problem is in the custom_breadcrumbs_nodeapi function, where the splitting of the values at \n takes place BEFORE replacing the tokens. I tried first to change order of the processing to replace tokens and after that split the titles, but without succes (obvisously, since I observed later that the replace of the token is for an entire title -> so you must enter a token on its own on a line). So I changed the code in order to have a second spliting done after the replacement of the tokens. Now I can for example set two tokens such as:

[my-breadcrumb-titles] = "WP5\nMeetings and Workshops\nSupported Events"
[trend-breadcrumb-paths]  = "private/wp5\nprivate/meetings-and-workshops\nprivate/wp5/supported_events";

And configure the use of the first one as the title, the second one as the path, resulting in the breadcrumb:
WP5 >> Meetings and Workshops >> Supported Events (each linked to the corresponding link).

What I have changed:

I have inserted the code below in the custom_breadcrumbs_nodeapi function, after the token replacement.

      $titles2=array();
      $paths2=array();
      for($i=0; $i < count($titles); $i++)
         {
          $tmp_titles = array_merge($titles2, preg_split("/[\n]+/", $titles[$i]));
          $titles2=$tmp_titles;
          $tmp_paths = array_merge($paths2,preg_split("/[\n]+/", $paths[$i]));
          $paths2=$tmp_paths;

         }
     $titles=$titles2;
     $paths=$paths2;

New code for the function:

function custom_breadcrumbs_nodeapi($node, $op, $teaser, $page) {
  if ($op == 'alter' && !$teaser && $page) {
    if ($breadcrumb = _custom_breadcrumbs_load_for_type($node)) {

      $titles = preg_split("/[\n]+/", $breadcrumb->titles);
      $paths = preg_split("/[\n]+/", $breadcrumb->paths);

      $titles = module_exists('token') ? token_replace($titles, 'node', $node) : $titles;
      $paths = module_exists('token') ? token_replace($paths, 'node', $node) : $paths;

/*Use of tokens for dynamic breadcrumbs*/
      $titles2=array();
      $paths2=array();
      for($i=0; $i < count($titles); $i++)
         {
          $tmp_titles = array_merge($titles2, preg_split("/[\n]+/", $titles[$i]));
          $titles2=$tmp_titles;
          $tmp_paths = array_merge($paths2,preg_split("/[\n]+/", $paths[$i]));
          $paths2=$tmp_paths;

         }
     $titles=$titles2;
     $paths=$paths2;
/*End change*/



      $trail = array(l(t('Home'), '<front>'));
      for ($i = 0; $i < count($titles); $i++) {
        $title = trim($titles[$i]);
        if (($title != '') && ($title != '<none>')) {
          // Create breadcrumb only if there is a title.
          $trail[] = _custom_breadcrumbs_create_crumb($title, trim($paths[$i]));
        }
      }
      drupal_set_breadcrumb($trail);
    }
  }
}

Please consider adding this functionality to yhe module.
It would be possible to have a different approach as well: first replace all tokens (but change code to allow a token inside the text, not only as a single value on the line) and after split the lines into titles array. I preffered the above approach which was simpler, but the alternate solution had the added value of allowing a breadcrumb containing a token AND other text.

CommentFileSizeAuthor
#3 custom_breadcrumb.patch1.21 KBrumburak
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Ludo.R’s picture

subscribing...

MGN’s picture

Version: 6.x-1.5 » 6.x-2.x-dev
Status: Patch (to be ported) » Active

Changing the status to active since there isn't a patch to port...

I think this is a little too specialized for custom breadcrumbs. It won't be implemented in 6.x-1.x since no new features are being added to that version. 6.x-2.x has the custom breadcrumbs identifiers module, which could be extended to do this, I believe. But I wouldn't want to alter the main custom breadcrumbs module.

rumburak’s picture

FileSize
1.21 KB

I am attaching a patch, so that anyone can apply the functionality. The patch is agains the latest 6.x-1.5 version.

MGN’s picture

Status: Active » Closed (won't fix)
kenorb’s picture

Status: Closed (won't fix) » Closed (outdated)