How to turn a view into tab for a specific node type only?

public
kirilius - Tue, 2007-12-18 20:39

Hello,

I have a view and the goal is to turn it into a tab that shows only for a specific node type. Here is what I do:

I have a page view called for e.g. x_pictures that is supposed to display all the pictures associated with a given node of type X. The URL I have given to it is node/$arg/pictures
In the "Menu" section of the page definition I have the following settings:

Provide Menu - checked
Provide Menu as Tab - checked
Make Default Menu Tab - NOT checked
Parent Menu Item Type - Already exists (don't create)

The view works fine and shows as a separate tab but on EVERY content type that I have. My goal is to have it displayed only for nodes of type X. How can I do that?

Thanks for the help!

Views Tabs?

mikey_p's picture
mikey_p - Tue, 2007-12-18 22:06

I'm not quite sure I understand you, but take a look at http://drupal.org/project/views_tabs. It may do exactly what you need. Let us now if it does or doesn't.


It is not possible. I did

gordon's picture
gordon - Tue, 2007-12-18 22:46

It is not possible. I did submit a patch a while back which allowed a snippet of php to be added to the menu assignment, but this was not really accepted.see http://drupal.org/node/64575


There is an undocumented and

merlinofchaos's picture
merlinofchaos - Tue, 2007-12-18 22:54

There is an undocumented and not entirely complete feature that you can use.

In place of $arg, put $node-CONTENTTYPE

But be careful that certain parts will generate incorrect URLs (because the code has not been adjusted to understand that $arg isn't the only replacement possible now) -- this is mostly only a problem with RSS feeds.


>In place of $arg, put

yngvewb - Tue, 2008-04-15 09:42

In place of $arg, put $node-CONTENTTYPE

Wow! This actually works!

In the view URL I put "$node-event/myview" and it only shows upp on content type event :-)

Custom menu hook

Crell@drupal.org's picture
Crell@drupal.org - Wed, 2007-12-19 06:18

What I've done in the past for that is to define the view without specifying the "Real" path I want it to live at, then in my hook_menu() implementation I add an entry for node/arg(1)/myview if the node is of the type I want. Then just specify the view_page() callback (or whatever the function is called). It's a bit clunky, but functional.


Well I was hoping for a

kirilius - Wed, 2007-12-19 07:04

Well I was hoping for a solution without any coding. The problem is that although I have good experience with web technologies, I have very limited Drupal exposure and I don't have experience with PHP.

I can try doing what you suggested, but can you please give me a little more detailed instructions?

I have the view, alright. Where should I look for the "hook_menu() implementation"? How do I "add an entry for node/arg(1)/myview"?

Thanks, I appreciate your help!

I did some experimenting and

kirilius - Thu, 2007-12-20 05:47

I did some experimenting and got some results but I am not sure I am doing the right thing. The reason is that I found multiple occurrences of hook_menu() in various modules.

I did the change you suggested in one of them - Node Hierarchy (the one that I am using to give me a relationship between a node and some pictures). The thing is that I am not sure this is the right place for it. Ideally where should I make the change?

Panels

Rob Loach's picture
Rob Loach - Fri, 2008-01-11 23:26

Panels 2 has the ability to do this. I suggest you try it out as a very good alternative.


I tried the Panels 2 module

kirilius - Fri, 2008-01-18 07:23

I tried the Panels 2 module but still don't see how to configure a tab to be displayed for a node type with it. I created a Bonus:Panels type of view, which works, but don't see how to display it as a tab?

Any hints?

Panels Tabs

Rob Loach's picture
Rob Loach - Sat, 2008-01-19 18:17

Wim Leers' Panels Tabs will let you do some cool stuff with Javascript tabs. The Drupal 6 menu system will really help with this stuff.


Thanks again! I was looking

kirilius - Sun, 2008-01-20 00:24

Thanks again! I was looking for a solution to add a regular Drupal tab to the node display. Panels Tabs will probably work, however it introduces a new type of tab.

If you are looking at a node that you just created, normally you have 2 tabs: View and Edit. What I want to do is to add a new tab on the same level for displaying node-related information. Much like in the user profile you see different tab for the different categories of fields in the profile.

Custom mini-module

raintonr's picture
raintonr - Fri, 2008-08-15 00:52

I had the same problem, the $node- didn't seem to work for me (and plus, don't like using features that might come and go) so wrote a small mini-module:

function ride_story_tabs_menu($may_cache) {
  $items = array();

  if (!$may_cache) {
    $add_tab = FALSE;
    if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) {
      $node = node_load(arg(1));
      if ($node->type == 'ride_story') { $add_tab = TRUE; }
    } else if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'tracks') {
      $add_tab = TRUE;
    }
    if ($add_tab) {
      $items[] = array(
        'title' => 'Tracks',
        'path' => 'node/' . arg(1) . '/tracks',
        'type' => MENU_LOCAL_TASK,
        'access' => 1
      );
    }
  }

  return $items;
}

YMMV, but seemed easy enough and works fine.