Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: How to Add a Tab to the Node’s Display?

Submitted by on April 2, 2010 – 6:41 amOne Comment

Problem
clip_image001

Display some information related to the current node and display that on a separate tab on the same level as View and Edit.

Solution

Adding of a tab in Drupal 6

Tab for all nodes without access restrictions:

$items[‘node/%node/new_tab’] = array(
‘title’ => ‘New Tab’,
‘page callback’ => ‘mycallback’,
‘page arguments’ => array(1),
‘access callback’ => TRUE,
‘type’ => MENU_LOCAL_TASK
)

For nods of specified type (‘my_type’ in this example):

$items[‘node/%my_node_type/new_tab’] = array(
‘title’ => ‘New Tab’,
‘page callback’ => ‘mycallback’,
‘page arguments’ => array(1),
‘access callback’ => TRUE,
‘type’ => MENU_LOCAL_TASK
)

function my_node_type_load($arg) {
$node = node_load($arg);
if($node->type == ‘my_type’)
return $node;
return FALSE;
}

Or you can do this when verification of menu item access rights:

/**
* Implementation of hook_menu().
*/

function my_module_menu() {
$items[‘node/%/new_tab’] = array(
‘title’ => ‘Pay Here’,
‘page callback’ => ‘mycallback’,
‘page arguments’ => array(1),
‘access callback’ => ‘custom_loader’,
‘access arguments’ => array(1),
‘type’ => MENU_LOCAL_TASK,
);
return $items;
}
function custom_loader($param) {
$node = node_load($param , $revision = NULL, $reset = NULL);
if($node->type == ‘my_node_type’)
return TRUE;
return FALSE;
}

Adding of a tab in Drupal 5

Here how you can add a tab to ‘my_type’ node. The tab will be shown to those users who can view the node:

if (arg(0) == ‘node’ && is_numeric(arg(1))) {
$node = node_load(arg(1));
if ($node->type == ‘my_type’) {
$items[] = array(
          ’path’ => ‘node/’. arg(1) .‘/images‘,
          ‘title’ => t(’Images’),
          ‘callback’ => ’show_tab_page’,
          ‘callback arguments’ => array($node),
          ‘access’ => node_access(’view’, $node),
          ‘type’ => MENU_CALLBACK);
}
}

One Comment »

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.