I found this issue (#354423: want menu tab to show only with certain content type) in my research of this issue, but it seems that, somewhere along the way, the ability to have a views-provided local menu task (along with 'View, Edit, etc.') only appear on one content type, through use of the contextual filters + validation, is gone.
I have a view set up with a page view, menu path node/%/subscribers, and a Contextual filter "Content: nid", and under that it's set to "Specify validation criteria, with the content type I'd like the tab to appear on checked.
However, the 'Subscribers' tab I've created still shows up on every node on my website.
If I create a custom module and define the tab on a per-content type basis in my own hook_menu, then it only shows up in that one content type (and not everywhere).
Comments
Comment #1
andypostLooks like menu access and contextual filter are different things, try to use page manager to define more granular access to menu item
Comment #2
geerlingguy commentedYes, I understand that... however, according to #354423: want menu tab to show only with certain content type and a few other posts I've found around here, Views provides some way of making a local menu task (menu tab) appear only on nodes of a set content type. But none of the methods mentioned (using arguments/contextual filters, or using a path of
node/$node-CONTENTTYPEin the menu path setting, works correctly for me in 7.x-3.x-dev.Comment #3
merlinofchaos commentedHm. That *shouldn't* be gone, actually. Maybe there's a bug causing this. Will investigate.
Comment #4
geerlingguy commentedFor now, as a workaround, I've implemented the following in my custom module:
And then, in the access callback, I only return TRUE for nodes on which I'd like the menu tab to appear. In the page callback, I have something like the following:
Comment #5
dawehnerIt works fine for me with this view
Can you please check as well and provide a view which does not work?
Comment #6
geerlingguy commentedI will do more testing and check back later.
Comment #7
acolyte26 commentedIt did not work for me. Even when I had contextual filter validation for content type it still shows up in all the nodes of all conten types.
Comment #8
acolyte26 commentedThis has been fixed in the latest release of views.
Comment #9
AndrzejG commentedSeems problem returned in rc3 version.
Specifically, if I create a path:
node/%/myview, with tab Myview
first for Bundle_a, and then for Bundle_b, the tab shows only for Bundle_b, despite contextual filter is set according to http://drupal.org/node/354423.
Clearing cache doesn't help.
Comment #10
nonprofit commentedAlthough this thread was closed years ago, it seems worth noting menu tabs can now be limited by content type by visiting advanced -> contextual filters -> specify validation criteria -> content -> [content types].
Comment #11
nathan tsai commentedIn case someone stumbles upon this for Drupal 8 as well:
https://peacocksoftware.com/blog/drupal-89-views-tab-only-certain-node-t...