Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This module works great for setting the menu position of nodes, but when i tried to set a view page to appear in the menu i can't get it to work.
I can tell that the rule is firing correctly, but the $active_trail doesn't get set to the trail that I expect to see. After adding the menu position path to the router item, the outcome of $active_trail = menu_set_active_trail(); is just
Comment | File | Size | Author |
---|---|---|---|
#9 | 1163868-menu-position-doesn-t-get-set-for-views-with-context.patch | 1.01 KB | mstrelan |
#8 | 1163868-menu-position-doesn-t-get-set-for-views-with-context.patch | 1.02 KB | mstrelan |
Comments
Comment #1
joelcollinsdc CreditAttribution: joelcollinsdc commentedthe last word got stripped but it should have said "home"
Comment #2
joelcollinsdc CreditAttribution: joelcollinsdc commentedI can only repeat this behavior when using the page display of a view when the view has an argument defined. if there is no argument defined for the view it works properly.
Comment #3
origaman CreditAttribution: origaman commented+1
Same with the Drupal 6 version... It doesn't work with views pages with arguments.
I've got a "concerts" view with path "concerts/%" so I can filter the concerts list by year supplied as an argument (e.g. "concerts/2007"). I set the menu position rule to "concerts/*" but this doesn't do anything...
Comment #4
joostvdl CreditAttribution: joostvdl commentedsubscribe
Comment #5
mstrelan CreditAttribution: mstrelan commented+1 on the module not working for views displays with arguments.
Comment #6
mstrelan CreditAttribution: mstrelan commentedUpdate: I *sometimes* can get this to work on views displays with arguments, but it is very sporadic. It seems to depend on what the parent item is. At first setting the parent to my "About" page wasn't working. I created a new page called zzz and added it to the menu and set that as the parent. It initially worked for my view display with args and then I moved it to my about page again, where it stopped working. I then moved it back to zzz and now that didn't work either. Can anybody make sense out of this?
Comment #7
mstrelan CreditAttribution: mstrelan commentedI am ever so close to finding a fix for this. Views module has a file views_plugin_display_page.inc which has a function
execute()
. This function calls$this->view->get_breadcrumb(TRUE);
which callsdrupal_set_breadcrumb($breadcrumb);
before menu_position gets tomenu_position_evaluate_rules()
.If you comment out
$this->view->get_breadcrumb(TRUE);
in views_plugin_display_page.inc then flush the cache it works perfectly. I have tried to cancel out what views has done by adding the following code to the top ofmenu_position_evaluate_rules()
but it doesn't help.I will keep going but I'm hoping someone who knows more about this can jump in now...
Comment #8
mstrelan CreditAttribution: mstrelan commentedI finally cracked it! My head is spinning. There is a patch attached, please review.
Comment #9
mstrelan CreditAttribution: mstrelan commentedThis one is a tiny bit better since it uses the path that is passed in to the function rather than $_GET['q'].
Comment #10
dalinWorks for me. Though I can't speak to the suitability of the approach - the menu system is a bit of a black box to me.
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedSeems to work well for me too.
Comment #12
carl.brown CreditAttribution: carl.brown commented#9 Is working for me too, with no visible side effects so far - Thanks!
Comment #13
keithm CreditAttribution: keithm commented@mstrelan: Nicely done. #9 works perfectly. Setting this RTBC.
Comment #14
romenov CreditAttribution: romenov commentedI'm not sure if this is relevant to this issue,
but for me this still not working for views page.
I have a view with path : stores , with contextual arguments (stores/all , stores/123 for example)
In my menu position rules I set a path based filter: stores/* and my language
But it doesn't get set to active, any suggestions?
Comment #15
JohnAlbinWhile working on the patch for #979464: Use menu_tree_set_path() to set the active trail of menu trees I ended up using a snippet of code that almost exactly matched the code in this patch. That patch will have to wait for Drupal 7.9 to come out before it lands, but I see no reason to use this patch in the mean time.
Comment #16
JohnAlbinThanks, Michael!
Fixed.
Comment #18
broonI've run into the same issue. I have a menu item called "News" which links to "/news" which is a view with arguments (if no argument is given through url views gets the current year and uses it as argument, e.g. 2013).
I have a different menu which lists all the years which are linked to their respective news view page, e.g. "2012" links to "news/2012".
Now, I want the original "News" menu item to be active if the current url is "news/*" and I added the rule. But the menu item becomes inactive as soon as I click a specific year link.
I tried the patch from #9 but wasn't successful since code changed in the meantime. Is this patch not included in 7.x-1.1?
I even tried to hack views module as in #7 but to no avail.
Any suggestions? Is this included in 7.x-2.x-dev?
Comment #19
dgastudio CreditAttribution: dgastudio commentedany update?
Comment #20
ioannis.cherouvim CreditAttribution: ioannis.cherouvim commentedany news on this?
Comment #21
Yuri CreditAttribution: Yuri commentedMy goodness....why is this not getting attention?
Comment #23
wturrell CreditAttribution: wturrell as a volunteer commentedI can't find an issue for this in Drupal 8 (and this issue is still marked as 'Active'…)
Does anyone else still have the same problem in D8?
Comment #24
wturrell CreditAttribution: wturrell as a volunteer commentedDrupal 8 update - this patch here:
#3027844: Unused conditions prevent rule activation when conditions have missing context
…which is from a few months ago, but was committed to the 1.0.0-alpha2 release earlier this month, means you can add a wildcard in the 'Pages' tab of the rule - e.g. /somepage/* - and menu_position will honour it for a view with a contextual filter.
So good news (and thanks to pstewart for writing it).
Comment #25
joelpittetClosing as outdated but feel free to correct me if you're still having issues with this.