I have a node type called XXXXX for example. When the node is displayed (by the author) usually there are two default tabs on the top:
View | Edit

Let's say I want to display some information related to the current node and I want to display that on a separate tab on the same level as View and Edit. So the tab line should look like this:
View | Edit | Related Information

The related information could be of any kind: static text, panels, blocks... ultimately I want to embed a view in this tab but the more general question is: How to add this tab for my node type XXXXX only?

Can you suggest some module(s) and settings, which allow for adding tabs without (with minimal) coding?

I know that Javascript Tools module provides tabs, also Panels module can be made to use those but all this is adding artificial visual tabs only. What I need is a real tab whit its own URL.

If a node's URL is http://mysite/node/111, much like the Edit tab loads in http://mysite/node/111/edit, I would like to add a new tab with an URL of type: http://mysite/node/111/new_tab

Thanks!

Comments

kirilius’s picture

Another drawback of the Panels 2 - Javascript Tools solution is that I get the tabs I want but the generic Drupal tabs (View and Edit) remain on top. It just doesn't look good to have two sets of tabs all related to the same node.

kirilius’s picture

Any ideas, please?

kirilius’s picture

Lots of ideas... I see ;-)

kirilius’s picture

Anyone?

danaktivix’s picture

I did something similar myself this week, and it took some hours to figure it out. Hopefully I have it roughly correct.

There's no non-coding way of doing this that I know of. I suggest making a new module (check drupal site for a starter module tutorial, if you haven't done one before. You'll just need the bare bones - a .module file and a .info file.)

I figured this out in part by adapting code from another module that uses tabs. By the way, could you let me know where you posted this in the forums, and I'll post this there too, see if people can't correct me where I'm going awry. This does work, but there may be an easier way, or problems with my interpretation of what Drupal is doing.

Three things to know before looking at the code:

  • The first thing to realise is that, in drupal code-speak, a tab is a 'MENU_LOCAL_TASK'.
  • Next - and sorry if you know this already - but Drupal works out where to put things / run code based on the path you give it. See the admin/settings/useraccounthelp path below: just by defining that path, Drupal knows to add it to the admin page.
  • Lastly, menu items are cached - so if and when you get your code working, be sure to empty the 'cache_menu' table: Drupal will rebuild it with your changes included. Otherwise you may not see the tab, even when the code's fine. A good frustrating hour spent changing code before I realised that one! (The devel module has a clear cache function, but I can't get it to work. I just use phpmyadmin and a bit of mysql - 'TRUNCATE TABLE cache_menu' will empty the table columns, leaving the table itself intact.)

Now, this is what I did. I wanted to add a 'help' tab to all profile account pages. I made a module and stuck in the following, (which I'd adapted from the subscriptions module - this also sticks a tab in people's profile. Always look for code to mimic!) (minus the php tags, which'll be in your module...)

The first part - admin/settings/useraccounthelp - just sets up an admin page for setting the URL the tab goes to. The settings function it calls is below, if you're interested. The key part is 'path' => "user/". arg(1) ."/".$helpurl. See here for what the arg function does. For your node problem, I guess you won't need to use the arg function coz you know what the node number is. I can't imagine you'll need to do the "if (arg" test either, though maybe you do - something like "if (arg(0) == 'taxonomy' && arg(2) == whatever your node type is.

It's "'type' => MENU_LOCAL_TASK" that makes the link a tab. Why not "'type' => TAB?" Christ only knows.

'callback' then tells it what function to call. I don't know if this is the quickest way of doing this, but my callback calls my send_to_help_page function, passing in the $helpurl. Then we get to the page I want via the drupalgoto function. Done.

Be interested to hear if that makes any sense and you can adapt it. Thought I'd better write since it took me so long to work out. I can't promise it's the best way of doing it, but it works for me. And don't forget to clear the cache!


/** 
 * Implementation of hook_menu(). 
 */ 
function accounthelptab_menu($may_cache) {
	
  $items = array(); 
  if ($may_cache) { 
    $items[] = array( 
      'path' => 'admin/settings/useraccounthelp', 
      'title' => t('User Account helppage settings'), 
      'description' => t('Choose the page that the user account help tab link goes to.'), 
      'callback' => 'drupal_get_form', 
      'callback arguments' => array('accounthelptab_admin_settings'), 
      'access' => user_access('administer site configuration') 
    ); 
	}
	
	//testing to make sure we're in a user profile...		
	if (arg(0) == 'user' && is_numeric(arg(1))) {
    

		$helpurl = variable_get('accounthelptab_url', 'userhelp');
		
    // User help page
     $items[] = array(
        'path' => "user/". arg(1) ."/".$helpurl,
        'title' => t('Help'),
				'weight' => 8,
				'callback' => 'send_to_help_page', 'callback arguments' => $helpurl, 
        //'access' => user_access('maintain own subscriptions'),
        'type' => MENU_LOCAL_TASK,
        );
		
	
	}
	
	return $items;
	
} 

function send_to_help_page($helpurl) {
	
	drupal_goto($path = $helpurl);
		
}

/** 
 * Define the settings form. 
 */ 
function accounthelptab_admin_settings() { 
  
	$form['accounthelptab_url'] = array( 
    '#type' => 'textfield', 
    '#title' => t('URL for the account help page'), 
  	'#description' => t('Enter the relative path for the user account help page.'), 
  	'#default_value' => variable_get('accounthelptab_url', 'userhelp'),
    '#title' => t('URL'),
    );
		
		return system_settings_form($form); 
} 


kirilius’s picture

Thanks, I replied with more details in the Drupal Dojo thread.