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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joelcollinsdc’s picture

the last word got stripped but it should have said "home"

joelcollinsdc’s picture

I 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.

origaman’s picture

+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...

joostvdl’s picture

subscribe

mstrelan’s picture

+1 on the module not working for views displays with arguments.

mstrelan’s picture

Version: 7.x-1.0-beta2 » 7.x-1.x-dev

Update: 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?

mstrelan’s picture

I 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 calls drupal_set_breadcrumb($breadcrumb); before menu_position gets to menu_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 of menu_position_evaluate_rules() but it doesn't help.

$last_item = array_pop(menu_get_active_trail());
if ($last_item['page_callback'] == 'views_page') {
  $trail = &drupal_static('menu_set_active_trail');
  $trail = NULL;
  unset($trail);
}

I will keep going but I'm hoping someone who knows more about this can jump in now...

mstrelan’s picture

Title: Can't get this to work for certain paths » Menu position doesn't get set for Views with contextual filters
Priority: Normal » Major
Status: Active » Needs review
FileSize
1.02 KB

I finally cracked it! My head is spinning. There is a patch attached, please review.

mstrelan’s picture

This one is a tiny bit better since it uses the path that is passed in to the function rather than $_GET['q'].

dalin’s picture

Works 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.

Anonymous’s picture

Seems to work well for me too.

carl.brown’s picture

#9 Is working for me too, with no visible side effects so far - Thanks!

keithm’s picture

Status: Needs review » Reviewed & tested by the community

@mstrelan: Nicely done. #9 works perfectly. Setting this RTBC.

romenov’s picture

I'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?

JohnAlbin’s picture

While 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.

JohnAlbin’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, Michael!

Fixed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

broon’s picture

Version: 7.x-1.x-dev » 7.x-1.1
Status: Closed (fixed) » Active

I'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?

dgastudio’s picture

Issue summary: View changes

any update?

ioannis.cherouvim’s picture

any news on this?

Yuri’s picture

My goodness....why is this not getting attention?

  • JohnAlbin committed 4f9f922 on 8.x-1.x
    Issue #1163868 by mstrelan: Menu position doesn't get set for Views with...
wturrell’s picture

I 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?

wturrell’s picture

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

joelpittet’s picture

Status: Active » Closed (outdated)

Closing as outdated but feel free to correct me if you're still having issues with this.