7

I'm using Drupal 6 and I'm trying to display two tab (menus) on a page that has the URL /vehicle_info. Both pages that the tabs link to should take a node's nid as parameter. My current code looks as follows:

  $items['vehicle_info/%/basic'] = array(
    'title' => t('Basic & Bookings'),
    'page arguments' => array(1),
    'access callback' => 'user_access',
    'access arguments' => array('administer fleet'),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 10
   );
  $items['vehicle_info/%/history'] = array(
    'title' => t('Service history'),
    'page callback' => 'vehicle_service_history',
    'page arguments' => array(1),
    'access arguments' => array('administer fleet'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 20
   );

I'm running into 2 issues:

  1. The tab "Service history" does not open the page "vehicle_service_history" (which is actually a view with the URL vehicle_service_history). It opens a page with the URL "vehicle_info/123/history", which does not exist (123 stands for the current nid).
  2. The default tab "Basic & Bookings" does not link to the URL "vehicle_info/123" but only to "vehicle_info".

What am I missing?

0

A couple of things seem to be missing here. The main confusion seems to be around page callback which should be a function not a URL. The URL is the key to your $items array.

  1. Your first menu item has no 'page callback'. This would be inherited from the parent item (keyed as $items['vehicle_info/%'] and a type of MENU_NORMAL_ITEM) if you had one, but you don't.
  2. Your second item menu seems to be confusing URL with callback as well. If you want it handled by a view then your page display on your view should handle the URL path vehicle_info/%/history, i.e. it will have a contextual filter. Does your view work like this?
0

If vehicles is a content type that happens to sit under the path 'vehicle_info' then you can simplify this a lot. Enhance the regular core tabs

$items['node/%node/basic'] = array(
  'title' => t('Basic & Bookings'),
  'page arguments' => array(1),
  'access callback' => 'vehicle_administer_fleet',
  'access arguments' => array(1),
  'type' => MENU_LOCAL_TASK,
  'weight' => 10
);
$items['node/%node/history'] = array(
  'title' => t('Service history'),
  'page callback' => 'vehicle_service_history',
  'page arguments' => array(1),
  'access callback' => 'vehicle_administer_fleet',
  'access arguments' => array(1),
  'type' => MENU_LOCAL_TASK,
  'weight' => 20
);

You will also need to define the custom access callback

function vehicle_administer_fleet($node) {
  return $node->type == 'vehicle' && user_access('administer fleet');
}

This is what drupal core does for it's own node tabs, more often then not, it is best to keep consistancy

  • Thanks, I'd like to try this but I'm not sure what you mean by "If vehicles is a content type that happens to sit under the path 'vehicle_info'". How can you set that a content type sits under a path? – drumming_cat Nov 13 '12 at 2:36
0

You went wrong way!!!
you can achieve completely what you want with views.

Create A views ,add your field as you want , set page Url to node/*/basic, in view Menu section (below page url) select menu tab with you title(see this for more info about create menu tab with views ). Also in Access section you can select who can see this page created by views.

I think you really don't Know how powerful really views is ;).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.