I've read the new menu documentation for D6 and implemented a hook_menu with the following code, which create a tab on each node .... fine.

 $items['node/%node/details'] = array(
    'title' => 'Details',
    'page callback' => 'node_mydetails',
    'page arguments' => array('Details',1),
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
    'type' => MENU_LOCAL_TASK,
  );

The problem is that I would like this "Details" tab to appear only on some content-type.
It sems to me that it's not possible given the new menu implementation in D6 and hook_menu being called only

rarely - for example when modules are enabled

.

Thanks for your support .... this a must have for me.

Comments

evil_marty’s picture

how about you use this, I haven't tested it but the idea should work.

<?php
$items['node/%my_node/details'] = array(
    'title' => 'Details',
    'page callback' => 'node_mydetails',
    'page arguments' => array('Details',1),
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
    'type' => MENU_LOCAL_TASK,
  );

.....

function my_node_load($nid) {
  if ($nid) {
    $node = node_load($nid);
    if ($node->type == 'my_node') {
      return $node;
    }
  }
}
?>

give it a try and set me know. Good luck =)

thx538’s picture

"my_node_load" is only invoked for "my_node" content-type btw

evil_marty’s picture

its just an example, all it is a custom loader function which is called when the menu is being constructed by drupal. Call it whatever you want, just make a function which takes an integer as an argument, load the node and check its type. If the function returns a value (ie. the node we want the menu for) then the link is used etc, if not then the menu is not shown or the page not found.

so intead make the function name my_node_menu_load and then in the menu array key use node/%my_node_menu_load/details. Remember to replace my_node with your module name or whatever.

thx538’s picture

It worked, except that the custom loader has to explicitly return FALSE if the test is unsuccessful.

 function my_node_menu_load($nid) {
  if ($nid) {
    $node = node_load($nid);
    if ($node->type == 'my_node') {
      return $nid;
    } 
  }
  return FALSE;
} 

Many thanks for your help ....

halmsx’s picture

many thanks for this solution.

nakeddesign’s picture

Good solution - Thanks

El Bandito’s picture

I'm wondering why a similar solution wasn't implemented via an access callback function as this seems a more appropriate way to solve the problem ( although I haven't tested it ) ?

El Bandito’s picture

This works for me and seems mildly more fit for purpose :

function MY_MODULE_menu() {

  $items['node/%node/proposal'] = array(
    'title' => 'Proposal',
    'page callback' => 'MY_MODULE_proposal',
     'page arguments' => array(1),  // sends $node to the page callback function
     'type' => MENU_LOCAL_TASK,
     'access callback' => 'MY_Module_ct_type_is',
     'access arguments' => array(1, 'course_version'),
  );

function MY_MODULE_ct_type_is($node, $type) {

  return ($node->type == $type) ? TRUE : FALSE;
  
}