Custom Breadcrumbs is very useful and has gotten me out of a number of jams, but I seem to have a situation where it's misbehaving. (Or perhaps I'm the one misbehaving!)

I have a path custom breadcrumb set with a wildcard like "/path/path2*". Due to the peculiarities of my site, however, I need to exempt nodes of a certain type from using this breadcrumb. So, in the breadcrumb visibility box, I place this code:

if ($node->type == 'myNodeType') {
  return FALSE;
}
return TRUE;

However, the breadcrumb was still used on nodes of type "myNodeType". When I added some debugging code, I discovered that the above snippet was executed 34 times for a single page load, and for all but one of those executions (something like the 27th), $node was undefined.

I guess my question is mostly this: What might cause the breadcrumb visibility code to be executed so many times? I assume the answer to that question will also tell me why I'm getting so many null values for $node.

I apologize if the question seems a bit vague; I'm a relative newcomer to Drupal, and I'm working on a site I inherited when another developer moved away.

Thanks in advance.

Comments

MGN’s picture

Status: Active » Postponed (maintainer needs more info)

Can you try the latest dev version and see if the code still behaves the same? There have been some updates that cache the custom breadcrumb to prevent this from happening.

Path type custom breadcrumbs can be defined on pages that are not nodes, so the breadcrumb may be set a couple of times during the page load. You might want to first check to make sure $node is defined and return FALSE if not.

Is there a reason you aren't using a node type breadcrumb to set the breadcrumb for node pages? It would be more efficient. When using wildcards on paths, every custom breadcrumb in the database needs to be loaded and checked for the "best" match. The option is there if you need to use it, but performance can be improved if you can avoid wildcards.

eaj’s picture

The path I'm using also sometimes matches views, so a node breadcrumb isn't really an option. I actually only want the breadcrumb to apply to the views, which makes a view breadcrumb seem like the obvious solution. I may end up just doing that, although it means creating identical custom breadcrumbs for each of six displays (since the view breadcrumb doesn't allow wildcards).

I'm not too fussed about the efficiency of the wildcards since we only have three custom breadcrumbs active, but it's useful to know.

The code snippet I posted does in fact return false if $node is undefined. The problem is that even for the node page, $node is undefined 33 of the 34 times the code gets run. I assume it's only the last time that matters--and that's not the one where it was defined.

I'll see if we can try the dev version later today. If I get a chance to try it, I'll post results here. I'm under some pressure to get this resolved, though, so I might end up going with the multiple view breadcrumbs.

Does page caching have any effect on these breadcrumbs? Doesn't seem like it should, but I've been surprised by cache behavior before.

Thanks for your help!

MGN’s picture

We have had trouble with views custom breadcrumbs when the views are cached. The hook that we use to modify the breadcrumb isn't called for cached views. I don't have a way around this at the moment. See #666724: views caching hides breadcrumb for more information on this problem.

eaj’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

It's entirely possible (even probable) that our problem was related to caching. We ended up going a drastically different direction in order to simplify our pages, so unfortunately I can't give you any more information. Thanks for your time and effort, though, it's much appreciated.

Marking as "can't reproduce"; I assume someone else will re-open if a similar problem crops up.