It doesn't look like the views custom breadcrumbs support in 6.x-2.0-beta2 really supports arguments.

I have two use cases for this:

Simple case:
My view path is path1/%, with the argument being a taxonomy term name. I want the breadcrumb to be My Menu Item | Term Name

More complex case:
View path is path2. If argument is present, it's path2/YYYYMM (calendar year and month), and it shows nodes from that year/month. If not, it's just path2, and it shows all nodes.

I want the breadcrumb to be My Menu Item 2 if there's no argument, and My Menu Item 2 | Month, Year if not.

I have used Views argument handling and it gets both of these partly right, but I need them to be correct, and I don't think there's a way to set this up in Custom Breadcrumb?

Comments

MGN’s picture

Status: Active » Postponed (maintainer needs more info)

I am afraid I don't understand this bug report.

Can you describe what you tried to do (What you put in the titles and paths fields, etc - I expect your results really depend on exactly what token you were using), what you were expecting to get for the breadcrumb, and the breadcrumb that you actually got? Also, how have you configured custom breadcrumbs? Do you have any submodules enabled, other than custom_breadcrumbs_views? What options are enabled?

There have been a couple of related bug fixes that have already been committed to 6.x-2.x-dev. You might also look at #623274: Use taxonomy breadcrumbs for views + multiple arguments and #680026: Custom Breadcrumbs doesn't work if view is provided a default argument to see if your issue may be related.

jhodgdon’s picture

Status: Postponed (maintainer needs more info) » Active

Sorry for being unclear! As a module maintainer myself, I always hate that. :)

OK. I'm now running Views 6.x-2.8 on my test box, and downloaded Custom Breadcrumbs 6.x-2.x-dev dated Feb 28, as well as Token. I've enabled the main Custom Breadcrumbs and the Custom Breadcrumbs Views, as well as Token, Views and Views UI.

Here is case (2) from my report -- if this case works, the simpler case will too.

In the Views UI, I enable the default "Monthly Archive" view (machine name "archive"). I have a couple of pieces of content on my site, so this gives me paths, page titles, and breadcrumbs (without doing anything yet in Custom Breadcrumbs):
archive : (title) Monthly archive : (breadrumbs) Home
archive/201003 : (title) March 2010 : (breadcrumbs) Home | Monthly Archive

[As a note, on the site I was actually working on, I also had the Menu Breadcrumbs module enabled, and that actually screwed these breadcrumbs up. But that's another story, and I see that your latest Custom Breadcrumbs looks like it includes that functionality -- so I'll have to try that. I hadn't noticed that before, since the Settings page is separate from the Build page, and they aren't linked...]

What I actually wanted for the breadcrumbs was for the page title to also be appended, as plain text (not a link):
archive : Home | Monthly Archive
archive/201003 : Home | Monthly Archive | March 2010

So I don't see a way to do set this up in Custom Breadcrumbs for this view. Two problems:
a) The breadcrumb should be different depending on whether the argument is present or not. This applies to case 2 but not case 1.
b) I don't see a way to get the "March 2010" from the argument or page title and tell Custom Breadcrumbs to use that. This applies to both Case 1 and Case 2.

Hope that's enough detail now. :)

MGN’s picture

Title: Views custom breadcrumbs doesn't support arguments » Improve handling of Views arguments by providing tokens for custom breadcrumbs
Category: bug » feature

Thanks. This seem more like a support request or a feature request than a bug report.

Right now, custom breadcrumbs has limited support for views arguments. It is used to provide access to taxonomy objects (for token subsitution) when a taxonomy argument is present. In your case, the argument doesn't lead to an object that is supported by tokens. And views doesn't provide tokens either. My recommendation is to create a custom (global scope) token using the tokenSTARTER kit that uses either the path or the views argument to construct the date pieces that you are interested in. This is a little redundant because views is already doing this. Unfortunately, I don't see an easy way for custom breadcrumbs to access this information via the views object.

a) The breadcrumb should be different depending on whether the argument is present or not. This applies to case 2 but not case 1.

This can be handled by setting up two custom breadcrumbs for the same view, and determine breadcrumb visibility with a little php snippet that checks for the present of an argument

See also #555190: Taxonomy breadcrumb with the taxonomy view and #641748: Custom Breadcrumb for use with Date Argument for more information.

Even your simple case isn't so simple, because it combines menu items, views and taxonomy terms!
You might try enabling the "Use the menu structure to set the breadcrumb trail", select the appropriate menu, and also enable 'Use the taxonomy hierarchy to set the breadcrumb trail for nodes and taxonomy pages', 'Append taxonomy breadcrumb trail to current breadcrumb for selected node types' , 'Show current taxonomy term in breadcrumb trail' and 'Use taxonomy-based breadcrumbs for views'

I haven't tested this, but it just might work.

jhodgdon’s picture

I ended up just putting in some code in the theme_breadcrumb() override in our theme's template.php file, which worked OK.

I'm not sure about your other suggestions, because in this case, it's not a taxonomy view, but a monthly archive.

Anyway, I think in this case that a token (or a placeholder thing) in Custom Breadcrumbs that would put in the current page title would have been enough for my purposes, because the page title is being set correctly.

Danny_Joris’s picture

Hi, I have the exact same issue as explained by jhodgdon. This would really be a nice feature. Actually I find it a very basic feature to have. In every website I build I have 2 or 3 pages like that, that need such breadcrumbs.

I'm going to try to see what token actions and starter is all about. In the meanwhile, jhodgdon, could you share the theme_breadcrumb() modifications you made? At this moment I have no clue how I am going to the dynamic titles of my archives view pages into my breadcrumb...

Any help is very welcome.
Cheers,
Danny

jhodgdon’s picture

Sure!

Something like this:

function poplarzen_breadcrumb($breadcrumb) {
  // Override breadcrumbs for some special cases.
  $pathargs = arg();
  // Here's the case for path news/tag/[tag name], which I want to be recognized as being underneath the News menu item.
  if (count($pathargs) == 3 && $pathargs[0] == 'news' && $pathargs[1] == 'tag') {
    // Tag archive page.
    // Fix breadcrumb.
    $breadcrumb = array(
      l('Home', '<front>'),
      l('News/Blog', 'news'),
      drupal_get_title(),
    );

    // Fix menu trail.
    $item = menu_get_item('news');
    menu_get_item($_GET['q'], $item);
  }

Hope this helps...

Danny_Joris’s picture

Thank you very much! It's a shortcut, but for now it works.

This is what I did:

<?php
function dannyjoris_breadcrumb($breadcrumb) {
  // Override breadcrumbs for some special cases.
  $pathargs = arg();
  // Here's the case for path tag/[tag name].
  if (count($pathargs) == 2 && $pathargs[0] == 'tags') {
    // Tags page.
    // Fix breadcrumb.
    $breadcrumb = array(
      l('Home', '<front>'),
      'Tag: '.drupal_get_title(),
    );

  }
  
  if (count($pathargs) == 2 && $pathargs[0] == 'archive') {
    // Archive page.
    // Fix breadcrumb.
    $breadcrumb = array(
      l('Home', '<front>'),
      l('Monthly archive', 'archive'),
      drupal_get_title(),
    );
  }

  if (!empty($breadcrumb)) {
    return '<div class="breadcrumb">'. implode(' &raquo; ', $breadcrumb) .'</div>';
  }  
}
?>

Thanks again! :)

crea’s picture

subscribe

mikebann’s picture

This looks like something i can use as well. Where did you put this code in the page template?

jhodgdon’s picture

Put it into your theme's template.php file.

jkopel’s picture

If you install the Page Title module it provides a [page-title] token that works quite well for this.
At least it does if your view is creating the page title from it's arguments.

Agileware’s picture

Subscribing, this would be very useful.

chris_huh’s picture

I'm trying to do something similar. I have a shop with categories (just the one level). I have a view that takes the argument from [tid] and gives it the url shop/%.

I have tried to set up the custom breadcrumbs to create the breadcrumbs like: Home|Shop|Argument title, but it always leaves out the Shop bit. I assumed this was because of the argument, since it works fine on some other views i have that don't use arguments.

I tried the template.php code above, but obviously haven't got it right:

function cakes_breadcrumb($breadcrumb) {

$pathargs = arg();

if (count($pathargs) == 1 && $pathargs[0] == 'tid') {

$breadcrumb = array(
l('Home', ''),
l('Cake gallery', 'shop'),
drupal_get_title(),
);

}
if (!empty($breadcrumb)) {
return '

';
}
}

I have put pathargs[0] as tid, but have no idea what that should be. I only have one level of arguments.

What am i doing wrong??

Cyberwolf’s picture

Subscribing.

sirkitree’s picture

I had a similar situation, but after a little debugging found it was not custom_breadcrumbs_views that was the problem, but token. I threw in a little debugging info there and found that the [catpath-raw] token is more appropriate for situations like this. Otherwise, the object that is used for replacement is the first node that the view results contains, and that is a bit unreliable as you might even get terms from a different category/vocabulary.

Andrew Gorokhovets’s picture

Subscribing.

TimG1’s picture

subscribing

lamp5’s picture

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