Posted by sifaan on June 27, 2008 at 10:13am
| Project: | Menu Breadcrumb |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | webrascal |
| Status: | needs work |
Issue Summary
Hi!
I am not sure if this is a bug, or is the intended functionality (in which case this becomes a feature request):
I have a menu item that points to a views-generated page. I've enabled the option to display the current node in the breadcrumbs, so I was expecting the link to appear, but it didn't.
A different menu item that points to a regular page works fine.
Is there any way to get it to work with a view?
Comments
#1
I have the same problem, I have Views and taxonomy/term/XXX aliased pages in my menu. Any plan to be able to get these contents to this nice breadcrumbs menu?
Thanks!
#2
I removed the manually assigned menu-item and enabled the menu-item on the views admin-page right below path. This fixed it.
#3
So close to perfect... but my views are secondary items off of Primary Links. I could have worked around this in 5, but am not seeing it in 6. Any tips?
#4
It seems like
hook_init()fires before the view's page code gets executed, which means the view has not calleddrupal_set_title()yet. (I don't think changing the module weight helps in this case, but I could be wrong.) I'm wondering if there is some other hook that can be used (other thanhook_init()) that would grab the page title after it has been set by the view (or any other module that is not a node but is setting the page title afterhook_init()is fired.)#5
For those who can't use #2 because they don't want the view page in the menu, this temporary solution is working for me. (And of course, any simpler solution/fix would be much appreciated.)
First, I put a
return;inmenu_breadcrumb_init()after it deals with themenu_breadcrumb_determine_menuvariable.Then, I copied all of the code after that point in
menu_breadcrumb_init()and copied it into a new<em>module</em>_preprocess_page(&$variables)function (you can put it into menu_breadcrumb.module as a quick-fix and call it menu_breadcrumb_preprocess_init, or dump it into your own module).This allows for
drupal_set_breadcrumbs()to be called after Views has done its thing, but before the page is rendered. There's one more step.<em>module</em>_preprocess_page()runs before the page is rendered but after the theme$variablesare rendered. So you'd need to manually update the breadcrumb variable, like so:$variables['breadcrumb'] = theme('breadcrumb', drupal_get_breadcrumb());(That would go at the bottom of the
<em>module</em>_preprocess_page()function that you've defined.)Note also that once you make the preprocess function, you'll have to go to the module and/or theme configuration page to get Drupal to reparse the module files for the existence of the preprocess function.
Like I said, this was a very quick fix for me because I'm under a project deadline to make the breadcrumbs work with Views, and I prefer being able to have the checkbox from menu_breadcrumb to control whether the page title is added to the breadcrumbs as opposed to having to modify my template file for every new project. Assuming I'm not missing some fatal flaw with this strategy, the code breadcrumb-specific code from
menu_breadcrumbs_init()could just be moved into a new<em>module</em>_preprocess_page()function.Either way, I'm not sure the breadcrumb stuff can happen in
hook_init, so either try my suggestion, or if you have a better approach/refinement to the above, I'd love to hear it.#6
Thanks PeteS.
I've gone and rolled a patch file to a similar end as your suggestions.
Works for us :)
#7
A quick addition to fix up html entities being double processed and rendered when displaying the current page as a link in the breadcrumb.
#8
Once more!
My html entities fix wasn't entirely right as I misunderstood the issue.
This fix is more appropriate.
#9
Following the applying patches instructions, this patch failed to apply for me. Using Drupal 6.10, Menu Breadcrumbs 6.x-1.1 (current release).
Here's my console output when running patch -p0 < menu_breadcrumb_7.patch:
(Stripping trailing CRs from patch.)
patching file menu_breadcrumb.module
Hunk #2 FAILED at 118.
1 out of 2 hunks FAILED -- saving rejects to file menu_breadcrumb.module.rej
Or if I run patch < menu_breadcrumb_7.patch:
(Stripping trailing CRs from patch.)patching file menu_breadcrumb.module
Hunk #2 FAILED at 118.
Content of menu_breadcrumb.module.rej:
***************
*** 135,138 ****
);
return system_settings_form($form);
}
--- 118,142 ----
);
return system_settings_form($form);
+ }
+
+ function menu_breadcrumb_preprocess(&$vars, $hook) {
+ if ($hook == 'page') {
+ $breadcrumb = drupal_get_breadcrumb();
+
+ if (variable_get('menu_breadcrumb_append_node_title', 0) == 1) {
+ if (variable_get('menu_breadcrumb_append_node_url', 0) == 1) {
+ $breadcrumb[] = l(drupal_get_title(), $_GET['q'], array('html' => true));
+ }
+ else {
+ $breadcrumb[] = drupal_get_title();
+ }
+ }
+
+ if (count($breadcrumb) == 1 && variable_get('menu_breadcrumb_hide_on_single_item', 0)) {
+ $breadcrumb = array();
+ }
+
+ $vars['breadcrumb'] = theme('breadcrumb', $breadcrumb);
+ }
}
#10
I opened the patch and applied the changes by hand on a clean copy of the module, and it had no effect (there is no visible effect of any change to the module's behavior so far as I can tell). I cleared all caches and the theme registry to be sure. I "think" the normal behavior of the module is still fine (e.g. nodes in the menu show a menu-based breadcrumb trail), but there is no effect on breadcrumbs of Views pages in the same menu.
Hope this helps.
#11
Is it possible that you need to go to the modules/themes administration page(s) after applying the patch, in order for Drupal to reparse the module to see that it now has a preprocess function? I'm not sure where that kind of data gets cached so clearing the cache/the cache tables may not cut it (while loading the themes/modules pages cause certain other pieces of internal data to get reset.)
#12
Sorry for the delay in following this up.
I'll look into it as soon as I can and push out a verifiable patch to go with the latest release.
#13
We were able to manually move Patch 7 (comment #8) into the menu breadcrumb.
We did have to the module and theme admin pages to resave our settings to get the preprocess function to fire. (comment #11)
However, we are still having problems seeing the complete breadcrumb when on a view page.
But on a node page the menu works completely.
For example, if we have 4 levels in our menu and the last level is a node, the breadcrumb works fine.
But if we are on the 3rd level, which is a view, the breadcrumb is incomplete.
Sometimes it will display a blank second item.
Or it may only have Home and the current.
#14
it works for views pages if the views are built correctly.
The views which create problems are the views accepting arguments.
The page view url needs a % where the arg is expected.
Even if there aren't any args afterwards. i.e. listing/%
Also, I had to hide the page when no arguments are present.
The setting for the argument sets what to do if no argument is present.
These two changes fixed #13.
NOTE: I manually patched the latest menu_breadcrumb
#15
This may be related: I just installed this module and it works fine even when it's on a Views-built page. For example, I rebuilt the /blog page in Views so I could rename the blog to be something other than "Blogs." So, for example, when viewing www.mysite.com/blog, it displays Home >> About >> My Cool Blog. Great.
However, when I go to a specific entry, it reverts "My Cool Blog" back to plain old "Blogs". It also doesn't nest correctly. So, for example, when I go to "Entry One", what I want is:
Home >> About >> My Cool Blog >> Entry One
...but what I get is:
Home >> Blogs >> Username's Blog
Bummer.
Related or should I start a fresh ticket for this?
p.
#16
I solved this problem (at least for now I don't see any issues) by entering taxonomy/term/xx link instead of my alias section/category links for menu items that point to views page that emulates taxonomy listings.
#17
@Keyz:
The problem is the menu_breadcrumb.module file doesn't end in a newline, and the patch tries to reference that incomplete line. If you add a newline (i.e. a blank line) to the end of menu_breadcrumb.module before applying the patch, it'll work.
#18
The patch failed
I have patched manually and works great for me ,
thank you !
note that views that have arguments must set the view path to hold the argument with %
.i.e news/%
Thanks again
here is the patched file attached for ver 1.1
#19
subscribing
#20
I applied the patch successfully and reapplied the theme. My Primary Menu structure is as follows:
About us (Page Node)
Structure (View Page)
History (Page Node)
When I'm at the bottom it comes perfectly:
Home » About us » Structure » History
but when I'm at Structure (the view page), it comes as:
Home » Structure
It is missing About us in between.
Is there anything I missed?
Thanks
#21
subscribed
#22
rajoo.sharma: Is the View page (Structure) in the Primary Links menu because of the Menu setting within the View page display itself, or because a link was manually added to the menu that points to the view page URL? If it's the last one, that would be one reason I can think of that it wouldn't work.
#23
Thanks Pete,
The view is a sublink, so it can not be added directly in view page, I had to add it in the primary menu.
Regards,
#24
I've updated the patch to apply to HEAD. The first hunk failed because that change is already in HEAD. Also had to change the patch to accept the missing newline at the end of the file. I'm marking it 'needs review'. Don't have time to read if it still needs other work to be worthy for committing. Sorry maintainer(s). :)
#25
sammys: Your patch doesn't remove the preprocess code from menu_breadcrumb_init(). I just looked at HEAD in the CVS browser, and that code is still in there (not surprising if the preprocess function hasn't been committed yet), so the patch does need to remove it.
I'm actually curious as to why menu_breadcrumb_preprocess() was used (with a consequent check for $hook == 'page') rather than menu_breadcrumb_preprocess_page() (suggested in #5, and which is called automatically for the 'page' hook). What was the reason for that? It seems cleaner to have all page preprocessing in *_preprocess_page() functions, if possible.
EDIT: deleted some totally incorrect nonsense that I'd written.
#26
Rolled a new version of this patch, based on #5 and tested by myself in #556552: Menu weights, black/white list, and memory of menu selection
#27
Does this piece of code also solves the issue related to views with arguments?
#28
Ok. Got it to work with the latest CVS version.
Now I have a new question. Is it possible to have the link clicked on the view page added to the breadcrumb? For example: I have a view listing members of a club. Every member has a node on which more information regarding his company is given. I do want to have the name added to the the breadcrumb, together with the name of the view page.
How to achiev this?
#29
See here:
http://drupal.org/node/496230
#30
subscribing
#31
@jweowu, on looking at the patch in #26 today, I think it must need to be taken with another of your associated issues from #556552: Menu weights, black/white list, and memory of menu selection.
#26 here removes drupal_set_breadcrumb(). Is that what you intended?
#32
this version applies cleanly on HEAD currently (update of patch from #26, which was complaining about reversed patch despite not having been applied). however i think i'm seeing no menu breadcrumbs after a quick test, so i've named the patch NEEDS_REVIEW as well :)
#33
I'll re-visit this when I get a chance.
Leaving out
drupal_set_breadcrumb()was on purpose. If all the processing is done inhook_init(), then you need to call it so that thedrupal_get_breadcrumb()in theme.inc retrieves the right thing, but with this patch, the processing happens subsequent totemplate_preprocess_page(), so I was thinking that there shouldn't be any need to 'set' the breadcrumb again.Thinking about it now, the theme itself may also wish to call
drupal_get_breadcrumb()and make more changes, so yeah, it should still set it.Oh, and something that I realised during the menu weights work is that this patch effectively stops menu_breadcrumb from working with books. The problem is that book.module calls
menu_set_active_menu_name()afterhook_init(), and ifdrupal_set_breadcrumb()hasn't been called already, then Drupal does amenu_get_active_breadcrumb()using the menu that book.module set.Glancing at the code, maybe we could call
drupal_set_breadcrumb()inhook_init()to circumvent that, but defer the rest untilmenu_breadcrumb_preprocess_page()? Or does that defeat the purpose of this patch? I'd need to test it to find out.Something to keep in mind, at any rate.
#34
this works for me. thanks
#36
Would this patch fix http://drupal.org/node/618700#comment-2531350 ?
#37
The patches produce an empty breadcrumb between home and the view name, so I had to modify the code:
/**
* theme('page') pre-processing.
*/
function menu_breadcrumb_preprocess_page(&$vars) {
$breadcrumb = drupal_get_breadcrumb();
$index = '';
if (empty($breadcrumb[count($breadcrumb)-1])) $index = count($breadcrumb)-1;
if (variable_get('menu_breadcrumb_append_node_title', 0) == 1) {
if (variable_get('menu_breadcrumb_append_node_url', 0) == 1) {
$options = array('html' => TRUE, 'attributes' => array('id' => 'menu-breadcrumb-title'));
$breadcrumb[$index] = l(drupal_get_title(), $_GET['q'], $options);
} else {
$breadcrumb[$index] = '<span id="menu-breadcrumb-title">' . drupal_get_title() . '</span>';
}
}
if (count($breadcrumb) == 1 && variable_get('menu_breadcrumb_hide_on_single_item', 0)) {
$breadcrumb = array();
}
$vars['breadcrumb'] = theme('breadcrumb', $breadcrumb);
}
Sorry, I don't know about creating patches.
#38
Hello,
I use the version 6.x-1.3, and it doesn't work for views, what patch should I apply?
Thanks in advance.
#39
Just disable the navigation menu in the breadcrumb settings page and it'll work for views.
#40
I've disabled the navigation menu, and it still doesn't work for views...
#41
Could regenerate breadcrumbs in hook_views_pre_view().
#42
Menu breadcrumb currently sets breadcrumbs for all pages in hook_init(). Currently other modules can override specific breadcrumbs later in the page generation process. E.g., in hook_nodeapi(), menutrails sets breadcrumbs based on a parent menu item by node type or node taxonomy term. Moving menu breadcrumb's breadcrumb setting to hook_preprocess_page() would break this, so hook_views_pre_view() might be preferable, though it might not resolve non-Views issues.
#43
Can you give me more details about #41 and #42? How can I do it?
#44
subscribe
#45
#46
39 works, but it prints the view name instead of the menu name. This isn't practical, for a view with arguments where the same view is used for different menu items based on arguments.
#47
#39 doesn't work for me. Creating a menu item for the view did, but it's not really what I was looking for...
#48
I have not tried to use patches, I tested solutions like #2. Nothing worked until I disabled breadcrumbs coming with Menu Trails module (enabled by default when this module is installed, so check this).
Now it works. But I have menu entry created for view page with view admin panel in Navigation menu, then manually disabled... Confusing.
#49
sub
#50
Subscribe.
#51
subscribe