Backend / DevOps / Architect
Brit by birth,
located worldwide

All content © Alex Shepherd 2008-2024
unless otherwise noted

Drupal - Views 3 menu tab visibilty

Published
0 min read
image
Image Credit: Unknown (if this is your work, reach out to me and I'll credit you!)

Hi guys,

Another Drupal 7/Views 3 howto for you this time. If you use a tab for your view's menu item (and have the path set to something like 'node/%/my_tab_name'), the default is for this tab to appear for all content types which come under the "node" bundle. This has rarely been what I want, so I'm going to show you how to restrict the visibility of the tab to certain content types.

It's done via the contextual filter settings. If you aren't using contextual filters, you can add a "Global: Null" filter, with the following setting:

  • WHEN THE FILTER VALUE IS NOT IN THE URL: Display all results for the specified field

To set the menu restriction, use the following settings:

  • Specify Validation Criteria: Yes
  • Validator: Content
  • Content Type: Tick the content type(s) on which you'd like the tab to appear
  • Filter Value Format: Node ID
  • Action to take if filter value does not validate: Show "Page not found"

Now apply your settings, and your tab should only appear on the relevant content types! I'm working fairly extensively with Drupal at the moment, so expect a few more posts of this ilk in the near future!

n00b