Is it possible to get views integration?

I have a set of views that have paths like "top/view1", "top/view2"... and I would like to have all these views to show under a menu items that happens to be at "top".

It would be nice if it was possible to map any path to a menu, an open ended list.

CommentFileSizeAuthor
#26 menutrails_views_support.patch489 byteschriscohen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

I vote for this feature too

ar-jan’s picture

Title: views integration? » Views integration for Menu Trails?
Category: support » feature

I just wanted to make this feature request and then it happened to be there already.

This would be a really cool feature. I am very happy with what Menu Trails does not, works very well to assign a specific content type to a specific menu and keep it active.
But when a view is rendered, I loose my active menu... I've had no luck trying other methods to keep the right menu active.

Any chance of this making it into Menu Trails?

steve22’s picture

Subscribe!
Would be great if we can make menu trail also work with aggregator pages (source and category pages) and user profile pages.

momper’s picture

subscribe +1

drewish’s picture

I guess I'm not understanding this issue... why can't you use's Views's menus? It seems to work fine for me.

momper’s picture

do you generate path + menuitem in views?
or only the path? ... and the menuitem in the menu-administration ...
and do you work with pathauto?

there must be a fine difference of the usage ...

ar-jan’s picture

Re #5 and #6, that could be the reason. I have not tried this since I already put all my views in nodes using Views Reference, but I was putting the menu items in the Menu administration, not in Views.

j0rd’s picture

I can't seem to figure out how to make this work with my views either.

Here's my setup.

/clothes -> page
/clothes/pants-list -> views page
/clothes/shirts-list -> views page
/clothes/shoes-list -> views page

then I display each clothes node, with pathauto under it's path

/clothes/pants-list/jeans
/clothes/shirts-list/polo-shirt
/clothes/shoes-list/rebook-shoe

So right now, I have my primary menu and secondary menu set to "Primary Menu" so when you click on clothes, you're displayed that page and then you enter a secondary menu of "Pants" "Shoes" "Shirts". I'd like the breadcrumb here to display "Home".

When you click on shoes list, I'd like it to show "Home > Clothes"

When you clikes on rebook, i'd like it to show "Home > Clothes > Shoes"

How can I make this work with Menu Trail? Maybe I'm missing something here...

frames’s picture

I can confirm this is working. This way:

1. Having a view with a menu item created in it (and obviously a path, which is mandatory). Works straight away.

2. Having a view and a menu item created from the menu module (the latter linking to the path defined in the view). Also works.

3. Having BOTH a view with a menu item created in it AND a menu item created from the menu.module at the same time (i.e., 1 + 2 above). First level (i.e. path defined in the view, e.g. "/dates") also works. BOTH menu items are "highlighted". BUT going to a second level (e.g. "/dates/2009") will only work for the menu item defined manually in the menu module.

I went even further and created:

a) a menu item in primary links created manually via menu.module
b) a menu item in secondary links created manually via menu.module
c) a menu item in secondary links created automatically via views

This case is just a variation of 3 above. The behaviour is the same: All the three links work for "/dates" (first level in the view). Only the menu items created from the menu module work going any deeper (e.g. "/dates/2009", "dates/2009/01" and so on).

CONCLUSION: Both menu items from the menu module and from views work. "Menu items created by hand in the menu.module" PREVAIL to "Menu items created in views". If you only have to show a menu item (regardless of being in primary or secondary links), both views menu items and "menu module items" are OK. If you have to show them twice and want all to show the menu trail info, just create menus by hand. As an aside, this is "safer" only for this case, but if you remove a view or modify its menu link, the menu created in the menu module won't disapear or follow the new path.

Hope I made sense.

frames’s picture

Category: feature » support

OK, once I tried to explain that this (and how) this is working, I'll try to explain why I think this SEEMS not to be working.

For those of you who do not see the "highligted menu", I believe this is because the theme you're using is not "menu-trails aware".

To check it, please do visit one of the pages where one of the links is "not working" for you. See the page source in your browser, look for the bit of text in the link you think should be highlighted. If you see an "active-trail" class in the li element "above" the a element which contains the text you're looking for, that is OK. Just something like this:

<li class="leaf last active-trail">
<a title="List of nodes by date" href="/dates">Dates</a>
</li>

To do what you want in a simple way, just go to the theme you are using (/sites/all/themes/xxx), open the stylesheet file (style.css, normally), look for every "active" class that you see there and "replicate" that with "active-trail". All this does is apply the same style to items classed as active (the Drupal default) and active-trail (the Menu Trails "default").

For instance, in the darkelegance theme, I had to change this for the sidebar:

.sidebar .content .active, .sidebar .content .active:hover {
        background:#444 url(images/sbar_act.gif) no-repeat 0 center;
        color: #EEE;
}

Into this:

.sidebar .content .active, .sidebar .content .active:hover, .sidebar .content .active-trail a, .sidebar .content .active a:hover {
        background:#444 url(images/sbar_act.gif) no-repeat 0 center;
        color: #EEE;
}

If you do not understand that, just call a friend who knows CSS, buy him a beer and show him this comment ;-)

I think this Issue should be closed, but I'll let someone of those that said this was not working test, confirm and close it (developers will thank you). I'll turn the Category back to "support request" since the feature was already there.

All the best.

frames’s picture

Just to let you know I have actually seen one view where menu-trails is not working for me. I have to investigate it further, but it is related to taxonomy terms and I am not sure it is actually working incorrectly.

While I check it, if some of you could also have a look at how your taxonomy-related views are working with menu trails, that would be cool.

Edit: As I imagined, the view and menu-trails is also working OK for taxonomy terms. I have a problem with something else, but I'm not sure if it's either Tagadelic, Tagadelic Views, or the way I set up my views and term paths (both are the same).

nullpainter’s picture

I also vote for this feature. The issue which I have which doesn't appear to be covered in the earlier posts, is that my view doesn't and shouldn't have a menu item.

I have a page on the website which displays the most recent blog item. On this page are links to blog categories. These blog categories pages are created by my view (using a page display type), which uses an views attribute to specify the category type.

To clarify, the URL of the blog is:
http://mysite/news_views/our_blog/

and a couple of paths to categories are:
http://mysite/news_views/our_blog/topic/1
http://mysite/news_views/our_blog/topic/2
http://mysite/news_views/our_blog/topic/3

The category page created by the view should not appear in my menu structure (and cannot, as it has an attribute), however needs to display the same menu as if the user was at the /news_views/our_blog/ path.

Clear as mud? ;)

nullpainter’s picture

As a workaround for my problem (namely, Menutrails not working for views that are exposed as pages and don't have associated menus), I wrote a function which arbitrarily sets the current menu path and uses Menutrails to set the breadcrumb as appropriate.

function rehone_menu($path) {
	$src = db_result(db_query("SELECT src FROM url_alias WHERE dst = '%s'", $path));

	$menu_item = menu_get_item($src);
	menu_set_item(NULL, $menu_item);
	if (variable_get('menutrails_breadcrumbs', 1)) {
		drupal_set_breadcrumb(menutrails_get_breadcrumbs());
	}
}

I then called the function in the header of my view:

rehone_menu('news_views/our_blog');

Hopefully this will be useful to someone!

tbannister’s picture

I have a situation that menu trails doesn't seem to handle for me:

I have primary navigation (across the top) and secondary navigation (on the left). The primary navigation corresponds to a series of different views. The secondary navigation corresponds to a set of taxonomy terms that each view accepts as a parameter. I would like to keep the current view and current term active on their respective menus. Ideally I would be able to use menu trails to say "If a view was passed this parameter, this menu item should be active". Similarly, I would have liked to be able to tell menu trails "If this view is used regardless of parameters, this menu item should be active".

I didn't see a way to do either of these in the current menu trails module.

jrabeemer’s picture

Menu trails should be made to work with anything that acts like a page, namely Views Page and Panels Page. There's no node data but clearly the need is there.

dynamind’s picture

Here's a thought:

menutrails.module:

/**
 * Implementation of hook_views_pre_view()
 *
 * This will be invoked on every view request before the view is themed, even if the view is cached
 */
function menutrails_views_pre_view(&$view, &$items) {
  if ($view->display_handler->display->display_plugin=='page') {
    drupal_set_breadcrumb(menutrails_get_breadcrumbs());
  }
}

Works for me. I wrote about it here: http://www.touchdesk.nl/2009/04/making-menutrails-work-with-views-2-in-d...

awolfey’s picture

subscribe

leenwebb’s picture

momendo has it exactly right -- there are things that act like pages that I want to use MenuTrails with. I'd love to see this functionality!

pmford’s picture

subscribe

TimG1’s picture

Yes please! Subscribing!

mclaren’s picture

dynamind's patch works perfect for me too! I think this should be committed!

phl3tch’s picture

dynamind's patch doesn't work for me. The path for my view has a wildcard. Could that be the reason?

Aside: is this module being maintained anymore? No commits since February 3.

glynster’s picture

Not sure if this will be of any help to you all but just in case here is a possible solution to maintaining your menu trail as active when using views.
You do not actually need to use Menu Trails for this.

1. Go to your view and edit the "page settings" and add a menu. Make sure this is "normal menu entry".
2. Save and you will have a new entry appear in your main menu.
3. Go to your site-building/menus and edit your main menu.
4. Drag the newly created "view tab" under the "parent navigation" you want the menu trail to be active on.
5. Here is the trick, disable the "view tab" so this will hide the tab link from the menu.

Now when going to this view your main menu which you wanted active will be active. You can have multiple levels of children and the main tab will always be active.

Hope this helps as it sure helped me and one less module needed in my config :)

chriscohen’s picture

Status: Active » Reviewed & tested by the community

dynamind's patch in comment #16 works a treat for me on 6.x-1.0 and 6.x-1.x-dev. I must admit I don't understand glynster in #23 at all. There are still no commits since February 2009, which is somewhat concerning given there are a number of patches waiting to be dropped into the dev branch. I'd like to see dynamind's patch committed.

Here is the situation for which the patch helped me:

  • Normal menu
  • A 'page' view, with a 'normal' menu item controlled from within the view
  • Without the patch, when on the view's page, the breadcrumb just says 'home'
  • After the patch, when on the view's page, the breadcrumb displays the path within the menu as expected
sun’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
Component: Miscellaneous » Code
Category: support » feature
Status: Reviewed & tested by the community » Needs work

Please submit a proper patch. See http://drupal.org/patch for more information.

chriscohen’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
489 bytes
sun’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for reporting, reviewing, and testing! Slightly fixed the coding style and committed to 6.x.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

jrabeemer’s picture

Does this support Panels pages?

Status: Fixed » Closed (fixed)

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

libeco’s picture

Status: Closed (fixed) » Needs work

Hi there,

I too (#22) can confirm that this patch does not seem to work for Views with arguments (like the taxonomy_term view provided by Views). I also have to confess I don't know how this patch could set a specified menu item to active.

I would also very much like to see a section to set a menu item to active for Views pages in the Menu Trails settings (I installed 6.x-1.x-dev and really had to look to find the new location admin/build/menu/trails, I had to look into the module file to find it actually :-P)

@ #23: while this method seems to work, it does seem to give an undesired result in the breadcrumb (or perhaps it somehow interferes with the Custom Breadcrumbs module).

pieterbezuijen’s picture

The solution of nullpainter works for me, I use arguments in my view...

I'd love to see this in Menu Trails though.

jaybee1001’s picture

Yes, nullpainter's solution works wonderfully for views with arguments. This would be cool to have in menu trails...

Bilmar’s picture

Hello, I was wondering if there is any update on Views integration of Menu Trails.
I installed the Dev version as I saw in #27 that the feature was developed and committed, but cannot seem to find the settings for views menu trails. I would appreciate any pointers. Thanks in advance!

momper’s picture

+1

jrefano’s picture

#13 works great for me. thanks a lot!

illuminatis’s picture

nullpainter's function works great for views and pages, nice work all of devs! ;)

Wolfgang Reszel’s picture

Category: feature » bug

Nullpainters function does not respect i18n. It always shows the default language for the view.

Xabraxas’s picture

My solution to the views/menutrails problem was to remove menutrails altogether and use the CSS Injector module to style the active menu links based on path. This may or may not work for you depending on your setup.

sun’s picture

Title: Views integration for Menu Trails? » Views integration
Category: bug » feature
Status: Needs work » Active

I'm unable to locate a new patch here.

EurekaLiz’s picture

Thanks Xabraxas, your solution was great! I had tried before every module for achieving this (menutrails, breadcrumbs, context, etc., etc.) but there was always a dead end. They never worked as they should, or there was a drupal core limitation, or something else! This time I just needed to display an active menu item for certain content types and taxonomies depending on the url, but it was impossible until I tried this simple solution.

So meanwhile a full working solution is made, this is the module I will be using http://drupal.org/project/css_injector.

jp.stacey’s picture

I wanted this very thing but I've worked out a stopgap. Hopefully helping with some of the problems where people turn to Views<->Menu Trails integration, I've now written some d.o documentation on Putting a View-with-wildcard into a menu hierarchy using Panels.

This solves some of the use cases of integration, where people want a view at /blog/term/!term to have the context of some other menu item. Not the ones where people have multiple views, though.

xjm’s picture

Tracking.

lucuhb’s picture

I am also interrested to display menutrail on page display of a view.
The solution I found is to add this in my template.php :

function myphptemplate_preprocess_views_view(&$vars){

        $view=$vars['view'];
        $menu_item = menu_get_item();
        if ($menu_item['page_callback'] == 'views_page'){
            //only for page display
            $term_trails = variable_get('menutrails_terms', array());
            $term=$view->args[0];
            $current_path = drupal_get_normal_path($_GET['q']);
            if (!empty($term_trails[$term])) {
                    //only if exists in menutrails_terms
                   $menu_item['href'] = $term_trails[$term];
                    menu_set_item($current_path,$menu_item);
           }
        }
}
druplicate’s picture

Using the CSS Injector module as suggested in #38 is a very simple solution if your site is hierarchically organized through the URL.

For example, if the URL is of the form: mysite.com/country/city/neighborhood/... and you're using a menu for selecting portions of a site based on "city", you just write CSS similar to this (in my case it's a custom menu button using the secondary menu):

#block-menu-secondary-links li.leaf.bangkok a,
#block-menu-secondary-links li.leaf.bangkok a:link,
#block-menu-secondary-links li.leaf.bangkok a:visited 
{
  color: #FFF;
}

#block-menu-secondary-links li.leaf.bangkok 
{
  background-color: red;
  color: #FFF;
  border: 1px solid white;
}

That changes the color scheme of the menu button the same way the 'active' class would when using the Menu Trails module.

Then select "pages" to inject this CSS only on the selected pages as thailand/bangkok/*, for example.

The key here is one additional module to assign a new CSS class with the same name as the menu item, to each 'li' element so you can target it. Just install the Menu CSS Names module and it happens automagically. Then it's just rinse and repeat for each menu item (city), a separate rule for each. Should you still need to use the Menu Trails module, this technique will work in parallel - if the Menu Trails module fails, this will take over. It works for any page even Views pages with paths that contain '%' for the argument.

andrewsuth’s picture

The patch from #26 does not work with Views pages that have dynamic paths such as node/%/mypage

I added this to menutrails_init() which has solved the issue for me.

  // Allow Menu Trails to set the active menu and breadcrumb
  // if the node_view is overwritten by the Views module
  if (module_exists('views') && 'node' == arg(0) && is_numeric(arg(1))) {
    $item = menu_get_item();
    // Check that it's a page generated by Views with a dynamic path.
    if ($item['page_callback'] == 'views_page' && strpos($item['path'], '/%')) {
      // Load the corresponding node.
      $node = node_load(arg(1));
      if (FALSE !== $node) {
        menutrails_nodeapi($node, 'view', NULL, TRUE);
      }
    }
  }

Idea borrowed from http://drupal.org/node/520106#comment-2487908

inetcom’s picture

Just in case someone looks for a solution whithout patching anything:
Use Insert View. You would use a regular content type e.g. page and with the activated input filter insert e.g.
[view:VIEWNAME=page_1=1]
VIEWNAME is the obviously the view's name.
page_1 is the first view
1 is the argument
You can add the page with a menu entry just as your are used to do.