Hi - setting up a large ecommerce site with Views handling the catalog pages (about 12,000 skus). Last item remaining... I need to maintain breadcrumb/menu active state when users click from a view page to a node. Can modify these in the product.module, if I can get the referring view - this is what I'm trying at the moment (in Drupal 5.2):
First Attempt:
<?php
$last_page = substr(referer_uri(), 29); //trimming off the domain, whats left is the views path
if ( preg_match("/store/", $last_page) ) { //match if coming from a view page, they all start with store...
menu_set_active_item($last_page);
} else {
$breadcrumb[] = l(t('Home'), '');
$breadcrumb[] = l(t('Product'), 'product');
drupal_set_breadcrumb($breadcrumb);
}
?>I thought this was working - but menu_set_active_item didn't just change the menu/breadcrumb but also resets the underlying $node object, or disconnects it somehow. I need this in blocks and other things to send to cart, etc.
Now trying drupal_set_breadcrumbs, also tried menu_set_location... but no results at the moment.
<?php
$last_page = substr(referer_uri(), 29);
$menupath = menu_get_item(NULL, $last_page, FALSE);
$breadcrumbs[] = l( $menupath->title, $menupath->path);
if ( preg_match("/store/", $last_page) ) {
drupal_set_breadcrumb($breadcrumbs);
} else {
drupal_set_breadcrumb($breadcrumb);
}
?>Anyone been down this road? I'm not seeing much in forums but I'm sure I'm not the first :)
Thanks for any help,
-Greg

Comments
This is working...
Found this helpful related post... http://www.angrydonuts.com/menu_set_location_can_eat_my_sho
For maintaining a breadcrumb/menu trail in a node when coming from a view, this is what I ended up with. It is working... but seems like a lotta code. Any better solutions welcome...
<?php$last_page = substr(referer_uri(), 29);
if ( preg_match("/store/", $last_page) ) {
$menupath = menu_get_item(NULL, $last_page, FALSE);
$items = array();
while ($menupath['pid']) {
$items[] = array('path' => $menupath['path'], 'title' => $menupath['title']);
$menupath = menu_get_item($menupath['pid']);
}
$items = array_reverse($items);
menu_set_location($items);
} else {
$breadcrumb[] = l('Home', null);
$breadcrumb[] .= l('Web Store', 'node/219');
drupal_set_breadcrumb($breadcrumb);
}
?>
Breadcrum Fix
Where did you insert this code
Dumb question from Views - PHP newbie
Thanks
Ron
Easy fix new module
http://drupal.org/project/custom_breadcrumbs
I had tried this before with no luck but new instructions made it a snap
bennybobw - June 13, 2007 - 15:52
As the name suggests, Custom Breadcrumbs allows you to create and modify your own breadcrumbs based on node type. After enabling the module, click on Administer > Site building > Custom breadcrumbs. On this page you'll see the option to add a new custom breadcrumb.
Clicking on that link, you have the option to select the node type the breadcrumb will apply to.
There are two text fields below-- "Titles" and "Paths." When creating a breadcrumb, you're simply creating a link. In the custom breadcrumbs interface "Titles" describes the text of the breadcrumb while "Paths" describes the Drupal path the breadcrumb links to. Each Title must have a corresponding Path. [Unfortunately, there's a bug so if you have a different number of Titles and Paths it will simply reload the form instead of showing the error (but you won't be able to save the breadcrumb).]
To give a very simple example of how to use this module, let's say I have a blog on my web site called "Deep Thoughts." To create this, I use the Views module to create a page at /blog that displays all the node types "blog post." Whenever a user views a blog post I want the breadcrumb to show Home > Deep Thoughts instead of simply Home. To do this I would simply type "Deep Thoughts" in the "Titles" field and and "blog" in the "Paths" field and save my breadcrumb.
Using the Tokens module, the Custom breadcrumbs module becomes much more flexible because my breadcrumbs can become dynamic. So I could create a breadcrumb like Home > Deep Thoughts > [Month of Blog Post] [Year of Blog Post] Where "Deep Thoughts" links to my main blog page and "[Month of Blog Post] [Year of Blog Post]" links to a view that shows only blog posts from the month and year the blog post was created (e.g. June 2007). To do this I would do the following:
Node Type:
Blog Post
Titles:
Deep Thoughts
[month] [yyyy]
Paths:
blog
blog/[mm]_[yyyy]
(where of course, blog/[mm]_[yyyy] is the path to the view of blog posts from that month and year).
So if I created a blog post today (June 13, 2007) my breadcrumb would show Home > Deep Thoughts > June 2007 and "June 2007" links to "blog/06_2007" which is a view of all blog posts from June 2007.
Also, note that Custom Breadcrumbs doesn't actually check to be sure that a particular path exists, so you'll have to check yourself to avoid 404 errors.
Hope this helps!
Great Work by Jeff Eaton made even more usable by bennybobw
Many thanks
Ron
There are modules for this
There are modules for this now, right?
Fun with Gmap