Drupal 7 hook menu validating argument from url
Under the 'Contextual Filters' settings on your View Display, click the 'Add' button to create a contextual filter for your Node ID.Typically you could use one of your node reference fields here as your contextual filter.These services should implement the Event Subscriber Interface, and are basically event listeners.The event subscribes have method get Subscribed Events that defines which events should be mapped to which methods.In the example screen shot above, we have various local task menu tabs when viewing a node as an admin user.The 'View', 'Edit' and 'Revisions' tabs are provided by Drupal Core, the 'Group' and 'Menus' tabs are provided by the Organic Groups module and the 'Devel' tab is provided by, you guessed it, the Devel module. When clicking on it, we want the page to display all the nodes related to the current node through a node reference field.So your best bet would be to use Joachim's comment linked above.1.Implement hook_menu_alter() to set a custom 'access callback' function on our views' page path /** * A custom 'access callback' function used by our view page display * to determine if its local task menu tab should show up or not.
A path like this is ready to take in a Node ID Views Contextual Filter, so the results are filtered on the node we are looking at.
Hi Tyler, Some time ago I did EXACTLY the same stuff as yours in my site, but in addition to filtering the "node type" where to show the Views tab, I had the need to hide the Views tab if the View returns no results. Next time I try placing a tab on a content type, I'll be sure to check out the 'specify validation criteria' on the view's contextual filter settings to see what options are available. So I think you'd have to create a custom module with local tasks via hook_menu() to accomplish this.
To do so the only solution I found was to programmatically execute the Views inside my 'access callback' and then return FALSE if the views returns no results. Thanks again for this Joachim, just today I needed this feature again, and the approach you mentioned works much better. Otherwise, perhaps one of the many contrib modules that build menus can be of use here.
You may have to tinker with your Contextual Filter settings for a while to get the results you want, be sure to use the 'Preview' mode in views and send along a Node ID to the preview. But what if you want this tab to only show up on a particular content type?
Once you have the results you want filtering on your node id, just save your view and you will now have a custom local task menu tab show up on all of your nodes! Because right now, it will show up on all content types.: See this comment for a much easier approach to controlling access to this tab.