Problem: when you navigate to a page that is a menu callback (with wildcards), and the parent of that page has no child menu links (callbacks with wildcards are not menu links, they are only menu router paths), then the page's parent is not included in the breadcrumb trail.
Example: on a D6 website, navigate to 'admin/content/book', and click 'edit order and titles' for one of the books on the site. The breadcrumb will read 'Home > Administer > Content management', whereas it should read 'Home > Administer > Content management > Books'.
Explanation: at the moment, the function menu_set_active_trail() (in menu.inc) is not only checking the 'in_active_trail' property of menu links, it is also checking to make sure that the 'below' property for each link is not empty. This should make sense - except that menu callbacks with wildcards, as well as 'local task' (i.e. tabbed) menu items, are never included in 'below'.
Solution: remove the checking of the 'below' attribute from menu_set_active_trail(). As far as I can tell, checking 'in_active_trail' should be reliable enough, and not checking 'below' shouldn't have any side effects.
Patch attached. With the patch applied, the breadcrumb on 'admin/content/book/%node' is corrected.
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | D7-active-trail-170309-32.patch | 878 bytes | pwolanin |
| #31 | D6-active-trail-170309-21.patch | 776 bytes | pasqualle |
| #30 | D7-active-trail-170309-21.patch | 762 bytes | pasqualle |
| #25 | breadcrumb_active_trail_fix_d62.patch | 802 bytes | Nick Urban |
| #21 | active-trail-170309-21.patch | 774 bytes | pwolanin |
Comments
Comment #1
keith.smith commentedIn working with aggregator this morning, I noticed it is also hit by this bug -- when one edits a feed, the breadcrumbs do not display correctly (see attached screenshot).
This patch no longer applied, so I rerolled it, and it solved the breadcrumb issue. I'm not qualified enough [yet] to really speak to the mechanics here, so I'll defer that to wiser souls among us.
Comment #2
robloachRelated issue.
Comment #3
keith.smith commentedBumping this up to the top of the list in the hope that a menu or breadcrumb guru will see it and review.
Comment #4
keith.smith commentedRerolling, since the previous patch had a good bit of fuzz.
As a note, I just tested this again, and the aggregator breadcrumbs (when editing a feed) are certainly incomplete without it (but are ok with it). There may be other similar instances in core as well.
Comment #5
keith.smith commentedThe patch in #4 applied to HEAD with a bit of offset so I re-rolled it.
The breadcrumbs are still incomplete when editing feeds in Aggregator (and possibly other places), and this patch still fixes it.
Comment #6
decafdennis commentedI hit this bug too.
All items with a wildcard in them are not showing up in
$curr['below']because they are being removed by_menu_tree_check_accessafter$item['access']has been set toFALSEin_menu_link_translate. The latter code (menu.inc:621) is accompanied with the following comment:// Note - skip callbacks without real values for their arguments.I think the core of the problem is that a router item is passed into
_menu_link_translatewhile that function expects a link item. Or_menu_link_translateis simply unwilling to deal with alink_pathwith a wildcard in it, while it should better deal with it since they do need to appear in breadcrumbs.Comment #7
decafdennis commentedThis patch will run the item through
_menu_translateif it's in the active trail and contains wildcards, instead of simply abandoning it. It appears this will fix this bug.I'm not certain this solution is any good.
Comment #8
pwolanin commentedmaybe this is only a problem for node links? There is some special-case code for them for access checking to improve performance.
Comment #9
decafdennis commentedpwolanin: no, this is not only a problem for node links. Please read the initial bug report.
Comment #10
pwolanin commentedah, right, well for local tasks this is a known problem, though I'm not sure about the patch code.
At the least, I think you need to use
_menu_translate($item, $map, TRUE);as is done here: http://api.drupal.org/api/function/menu_local_tasks/6Comment #11
pwolanin commentedon node/2/edit or admin/settings/filters/1
Comment #12
decafdennis commentedpwolanin: just to clarify, this problem is not only happening with local tasks. It's happening with everything that has a wildcard as one of it's ancestors.
I'll just set the status back to active until a menu-guru takes a look at this.
Maybe this issue should be marked as critical, since it would be bad, I think, if something simple as breadcrumbs don't fully work when 6.0 is released, while they did work in 5.x.
Comment #13
cwgordon7 commentedMarked http://drupal.org/node/220084 as a duplicate. Perhaps http://drupal.org/node/184955 and http://drupal.org/node/139015 are duplicates too?
Comment #14
gábor hojtsyI said there already that "breadcrumb does not always include all active items" does not make your site horribly broken, so does not mandate a critical flag. I'd be surprised if the breadcrumb would be such an important part of any website.
Comment #15
moshe weitzman commentedConfirmed that this is still a problem. I don't think it quite qualifies as a critical though.
Comment #16
decafdennis commentedGábor: if the breadcrumb is inconsistent then users might get confused when navigating the site. Additionally, sometimes the breadcrumb allows you to navigate back to a page that is not always linked in the navigation menu.
But indeed: critical, no.
Comment #17
pasquallePatch in #5 fixed two different breadcrumb issues for me.
Please give it an another review, and set it to RTBC.
Comment #18
pwolanin commentedDoesn't this patch in #5 throw a warning?
if there is nothing below, the 'below' element is set to FALSE: http://api.drupal.org/api/function/_menu_tree_data/6
Do you see the error:
Comment #19
pasqualle@pwolanin I did not see this warning yet. Do you know any page which should throw the warning?
Comment #20
pasquallePatch in #5 fixed these breadcrumbs for me:
(note: The described examples are in simplified form and may have functional differences with my actual tests)
issue1: callback 2 level deeper, shows correct breadcrumb now
issue2: callback under menu_suggested_item shows the title (Test) in breadcrumb
It would be better for me if I could change menu_suggested_item to callback, but in that case the breadcrumb does not show up.
---
issue3: I am still struggling with other problem
test/%wcard1/add -> shows correct breadcrumb "Test > %wcard1 (changed to correct title)"
test/%wcard1/edit/%wcard2 -> shows breadcrumb "Home" (I thought it should work, because issue1 and issue2 works..)
Comment #21
pwolanin commentedmaybe something like this? Otherwise I think you are trying to run
each()on a variable that == FALSE;Comment #22
pasqualleThe last change in the patch seems logical, but can't test it because I haven't seen the warning..
Is there any chance that there will be a solution for issue3? I am trying to create the correct menu structure for my module, which is without collisions (see issue #220407: Fix collisions in admin menu). This seems like a good structure for me, but the breadcrumb and the actual menu item is totally lost.
Comment #23
robloachSubscribing. This effects the Services module in Drupal 6.
Comment #24
mayco commentedI stumbled on this bug with a different use case
I created a module that used a wildcard, and as long as the module was in the navigation menu, everything was fine, but when I moved it to a custom menu, the breadcrumb was incorrect.
It seems that the menu_get_active_menu_name() returned a wrong menu.
I fixed it by adding the following lines in menu_set_active_trail( ... )
// Retrieve the menu item using the root path after wildcard replacement.
$root_item = menu_get_item(implode('/', $parts));
if ($root_item && $root_item['access']) {
$item = $root_item;
}
}
+ $menu_link = menu_link_load(db_result(db_query("SELECT mlid FROM {menu_links} WHERE link_path = '%s'", $item['path'])));
+ menu_set_active_menu_name($menu_link['menu_name']);
$tree = menu_tree_page_data(menu_get_active_menu_name());
list($key, $curr) = each($tree);
while ($curr) {
// Terminate the loop when we find the current path in the active trail.
Comment #25
Nick Urban commentedI encountered both of these problems too.
My solution was a combination of merely changing the if ($curr['below']... to if (is_array($curr['below']...
And I also made use the very helpful suggestion from mayco, which allows this to work on menus other than navigation.
However if I go to a page like admin/content/node-type/book/delete, there are no breadcrumb links, only Home.
So something is still not quite right. Here is my final patch, which solves my particular problem, but FYI it is against 6.2, not HEAD.
Comment #26
ebruts commentedsubscribing. this really needs to be fixed.
Comment #27
pasquallethere is also a module with the same functionality as your patch..
http://drupal.org/project/menu_breadcrumb
Comment #28
pasquallecan we commit the patch in #21, and open another issues for the remaining problems?
that would be a huge help for me..
Comment #29
robloachWe'll have to commit it to the Drupal 7 branch first, and then backport it to 6.
Comment #30
pasquallepatch #21 for Drupal 7
Comment #31
pasquallepatch #21 for Drupal 6
Comment #32
pwolanin commentedI think this is the best solution code-wise, and is a very minor change. I re-rolled the patch for 7.x to improve the code comment.
Same patch applies to Drupal 6 with offset.
Comment #33
merlinofchaos commentedPatch in #32 fixes the problem I reported in http://drupal.org/node/258660 for D6. +1 from me.
Comment #34
dries commentedI've committed this to CVS HEAD. I leave it to Gabor to decide whether this needs to be backported to Drupal 6, and if the current patch qualifies. Thanks all!
Comment #35
merlinofchaos commentedIMO, this is a bug in Drupal 6, and this patch should qualify as a bug fix. In my opinion, of course.
Comment #36
pwolanin commentedThanks Dries. This is a bug and by no means a feature - so I think it should go in D6 also.
Comment #37
gábor hojtsyThanks. The latest patch applied with a small offset to D6. Looked good, committed.
Comment #38
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #39
andreas1984 commentedmenu_get_active_menu_name
seems to allways return navigation. I think its a related bug so i post it here drupal version 6.15