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

andypost’s picture

Looks like menu access and contextual filter are different things, try to use page manager to define more granular access to menu item

geerlingguy’s picture

Yes, 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-CONTENTTYPE in the menu path setting, works correctly for me in 7.x-3.x-dev.

merlinofchaos’s picture

Hm. That *shouldn't* be gone, actually. Maybe there's a bug causing this. Will investigate.

geerlingguy’s picture

For now, as a workaround, I've implemented the following in my custom module:

/**
 * Implements hook_menu().
 */
function custom_menu() {
  $items['node/%node/subscribers'] = array(
    'title' => 'Subscribers',
    'page callback' => 'custom_subscribers',
    'page arguments' => array(1),
    'access callback' => 'custom_access',
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
    'weight' => 1,
  );

  return $items;
}

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:

/**
 * Subscribers page callback.
 */
function custom_subscribers($node) {
  return views_embed_view('subscribers', 'page', $node->nid);
}
dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

It works fine for me with this view


$view = new view;
$view->name = 'validate_nodetype';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'validate_nodetype';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'validate_nodetype';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['nid']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['nid']['specify_validation'] = 1;
$handler->display->display_options['arguments']['nid']['validate']['type'] = 'node';
$handler->display->display_options['arguments']['nid']['validate_options']['types'] = array(
  'article' => 'article',
);
$handler->display->display_options['arguments']['nid']['validate_options']['access'] = 0;
$handler->display->display_options['arguments']['nid']['break_phrase'] = 0;
$handler->display->display_options['arguments']['nid']['not'] = 0;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'node/%/story';
$translatables['validate_nodetype'] = array(
  t('Master'),
  t('validate_nodetype'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('All'),
  t('Page'),
);

Can you please check as well and provide a view which does not work?

geerlingguy’s picture

I will do more testing and check back later.

acolyte26’s picture

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

acolyte26’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

This has been fixed in the latest release of views.

AndrzejG’s picture

Version: 7.x-3.x-dev » 7.x-3.0-rc3

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

nonprofit’s picture

Issue summary: View changes

Although 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].

nathan tsai’s picture

In case someone stumbles upon this for Drupal 8 as well:

https://peacocksoftware.com/blog/drupal-89-views-tab-only-certain-node-t...