Improve Drupal permission system: administer taxonomy term & administer menu item

Whenever a new comer asks me about how to start with Drupal, I always warn him about Drupal's high learning curve and lack of usability before giving him advices. It's not only applied for developers, but also for end-users. This case is an example:

This time, my friend asks me about how to limit user access to taxonomy vocabulary term and menu item. In detail:

  • User can create / edit / delete taxonomy term
  • User can not create / edit / delete vocabulary
  • User can create / edit / delete menu item
  • User can not create / edit / delete menu

The reason he want to limit user access in that way because the person who manages this website is not well-educated in IT, so restrict user permission is a way to make him easier to work. But Drupal is lacking of this permission detail. We can use vocabulary permissions modules but this is unnecessary here. The question is why Drupal core developers do not develop this kind of permission for taxonomy and menu, like the way they do with node. Well, I'm not going to blame anyone, just a question and suggestion.

And here I solve the problem. I write a custom module, a very simple one, to alter menu permission to another functions, which added addition permission. The code is as simple as below:

function istar_admin_perm() {
return array('administer taxonomy term');
}

function istar_admin_menu_alter(&$menu) {
$access_map = array(
// taxonomy permission
'istar_admin_access_admin_taxonomy_term' => array(
'admin/content/taxonomy',
'admin/content/taxonomy/edit/term',
'admin/content/taxonomy/%taxonomy_vocabulary',
'admin/content/taxonomy/%taxonomy_vocabulary/add/term',
),
);

foreach ($access_map as $access_callback => $access_menus) {
foreach ($access_menus as $path) {
$menu[$path]['access callback'] = $access_callback;
}
}
}

function istar_admin_access_admin_taxonomy_term($right) {
return user_access($right) || user_access('administer taxonomy term');
}

I removed the part for menu item permission, but it would be the same with taxonomy term. This may raise a problem when we disable the module and the access callback function does not exist any more, I leave the `unisntall` part for you. If you have any suggestion on Drupal permission, and you need to help then you can always contact me in the contact form, or leave a comment below :D

Add new comment