Reputation: 6919
I have a module that creates several admin/settings/modname
pages.
I created a new role.
I want this role to only be able to access one specific page, say admin/setting/modname/custom1
How would I go about assigning access right only to that page to this role?
Would this be done under my hook_menu
under access arguments
?
Right now, the role gets Access Denied on all pages.
Upvotes: 0
Views: 774
Reputation: 36955
You can implement hook_perm
to provide a set of custom permissions for your module:
function mymodule_perm() {
return array('my module permission');
}
And then in your menu item in hook_menu
use the access arguments
as you suggest:
function mymodule_menu() {
$items['admin/setting/modname/custom1'] = array(
'title' => 'Settings',
'page callback' => 'mymodule_callback',
'access arguments' => array('my module permission')
);
return $items;
}
Once you've installed your module/cleared Drupal's caches go to the permissions admin page and grant your new permission to the required role and users with that role will (in theory) be able to access it.
I say "in theory" because if your path resides under admin/
then the role will also need the access administration pages
permission in order to view the page, which would introduce potential security issues. Your best bet would be to change the path to somewhere other than admin/
to avoid having to deal with this.
Upvotes: 2