Doesn't work for Views pages

sifaan - June 27, 2008 - 10:13
Project:Menu Breadcrumb
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:webrascal
Status:needs review
Description

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?

#1

teecee - January 15, 2009 - 13:01

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

japanitrat - January 30, 2009 - 14:18

I removed the manually assigned menu-item and enabled the menu-item on the views admin-page right below path. This fixed it.

#3

MindiL - February 12, 2009 - 07:51

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

PeteS - March 1, 2009 - 17:57

It seems like hook_init() fires before the view's page code gets executed, which means the view has not called drupal_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 than hook_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 after hook_init() is fired.)

#5

PeteS - March 2, 2009 - 04:58

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; in menu_breadcrumb_init() after it deals with the menu_breadcrumb_determine_menu variable.

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 $variables are 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

webrascal - March 2, 2009 - 22:18
Assigned to:Anonymous» webrascal
Status:active» needs review

Thanks PeteS.

I've gone and rolled a patch file to a similar end as your suggestions.

Works for us :)

AttachmentSize
menu_breadcrumb.patch 1.51 KB

#7

webrascal - March 2, 2009 - 22:29

A quick addition to fix up html entities being double processed and rendered when displaying the current page as a link in the breadcrumb.

AttachmentSize
menu_breadcrumb.patch 1.53 KB

#8

webrascal - March 3, 2009 - 22:01

Once more!

My html entities fix wasn't entirely right as I misunderstood the issue.

This fix is more appropriate.

AttachmentSize
menu_breadcrumb.patch 1.54 KB

#9

Keyz - March 9, 2009 - 22:06

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

Keyz - March 9, 2009 - 22:23
Status:needs review» needs work

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

PeteS - March 10, 2009 - 18:39

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

webrascal - March 23, 2009 - 19:54

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

pelicani - April 3, 2009 - 16:10

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

pelicani - April 3, 2009 - 22:19

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

pbeakley - April 10, 2009 - 23:27

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

wexy - May 14, 2009 - 15:12

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

wesayso - May 27, 2009 - 18:43

@Keyz:

Hunk #2 FAILED at 118.

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

avior - May 28, 2009 - 08:33

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

AttachmentSize
menu_breadcrumb.module.txt 4.99 KB

#19

rismondo - May 31, 2009 - 00:46

subscribing

#20

rajoo.sharma - June 5, 2009 - 09:31

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

xarbot - June 20, 2009 - 21:41

subscribed

#22

PeteS - June 22, 2009 - 03:29

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

rajoo.sharma - June 27, 2009 - 13:07

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

sammys - July 12, 2009 - 21:09
Status:needs work» needs review

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). :)

AttachmentSize
275622_200907121705-0400.patch 903 bytes

#25

jweowu - July 20, 2009 - 04:15
Status:needs review» needs work

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

jweowu - October 3, 2009 - 22:27
Version:6.x-1.1» 6.x-1.x-dev
Status:needs work» needs review

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

AttachmentSize
mb_theme.patch 1.77 KB

#27

Maroli - October 16, 2009 - 07:04

Does this piece of code also solves the issue related to views with arguments?

#28

Maroli - October 16, 2009 - 07:23

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

jweowu - October 16, 2009 - 07:49
 
 

Drupal is a registered trademark of Dries Buytaert.