2
votes

I am currently using Drupal 7 and I am writing a custom code such that users with a certain permission("use business dashboard") should see a menu item in their main menu. The problem is that only I(admin) can see this menu item. I have been able to create a custom permission on the permissions page and have set it to give access to "admin" and my user-specific role and have implemented the following code(nevermind the "xxxxxx" that is inplace of the module name, I would rather keep it anonymous for now, but just know that they are all in place of the machine-readable module name):

function xxxxxx_menu(){
$items = array();

$items['xxxxxxx'] = array(
    'title' => 'Business Owner Dashboard',
    'page callback' => '_xxxxxx_page',
    'access arguments' => array('use business dashboard'),
    'type' => MENU_NORMAL_ITEM,
);
return $items;
}

function xxxxxx_permission(){
    return array(
            'use business dashboard' => array(
            'title' => t('Have access to business dashboard'),
            'description' => t('Allow user to send out SMS messages via         database query forms'),
        ),
    );
}

When I log in as my test user which has the role-specific permission of "use business dashboard" I cannot see the menu item. I am sure this is incredibly simple, but I have been Googling and prodding at the code for hours. Any help would be greatly appreciated!

1

1 Answers

3
votes

Can't figure this out either. Can you try to break down the access callback, if it didn't work, at least it'll give you a tip about what's going on.

Your code can go like this:

function xxxxxx_menu(){
$items = array();

$items['xxxxxxx'] = array(
    'title' => 'Business Owner Dashboard',
    'page callback' => '_xxxxxx_page',
    'access callback' => 'my_custom_access_callback',
    'type' => MENU_NORMAL_ITEM,
);
return $items;
}

function my_custom_access_callback()
{
    if(user_access('use business dashboard'))
        return TRUE;

    return FALSE;
}

Till me if this works... Muhammad.