0

I have a new module I made called kameleon_create_report, and I want to add a menu item to Reports. So I created my .module

<?php
function create_report() {
    print "test";
}

function kameleon_create_report_menu() {
    $items['admin/reports/orderreport'] = array(
        'title' => 'Order Report',
        'page callback' => 'create_report',
        'weight' => 1,
        'type' => MENU_LOCAL_TASK
      );
}
?>

And the info

; $Id$
name = Create Report
description = Report generator for orders
core = 6.x

But it's not showing up, even after a refresh.

2 Answers 2

3

You're missing one of either access callback or access arguments:

From the hook_menu() docs:

"access callback": A function returning TRUE if the user has access rights to this menu item, and FALSE if not. It can also be a boolean constant instead of a function, and you can also use numeric values (will be cast to boolean). Defaults to user_access() unless a value is inherited from the parent menu item; only MENU_DEFAULT_LOCAL_TASK items can inherit access callbacks. To use the user_access() default callback, you must specify the permission to check as 'access arguments'

Sorry to paste so much but it's all relevant, the last sentence in particular.

Choose a permission that applies to your site and added it to your menu item:

function kameleon_create_report_menu() {
  $items['admin/reports/orderreport'] = array(
    'title' => 'Order Report',
    'page callback' => 'create_report',
    'access arguments' => array('access content'), // This is almost certainly NOT the permission you want to use, choose one with restricted access.
    'weight' => 1,
    'type' => MENU_LOCAL_TASK
  );

  return $items;
}

Also as Attiks points out you've forgotten to return $items from the menu hook.

Finally, simply refreshing the page won't work when you add a menu item (they are cached), so you need to clear Drupal's caches to see the new item.

2

You forget the return $items line.

Also rename create_report to kameleon_create_report_create_report to avoid namespace clashes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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