Show only the relevant admin menu items to your content manager

13 Sep 2011

Joris Snoek - Business Dev
+31 (0)20 - 261 14 99

Ever wanted to show your customers only the menu items in the Admin menu you want them to see? That is possible.

Drupal has a magnificent access control system, where you can cleanly build a sophisticated user access management system. But Drupal out of the box has some 'thoughts' of it's own concerning configuring of some access restrictions. Some of the access restrictons are bundled. So if you give access to a certain admin-area, it is possible you also provide 'bundled' access to another area.

For example: The 'Administer menu' permission, provides access to add/edit menu items. But also grants access to administer the menu. The first one is perfect for content managers, the second one: you don't want your content manager to add/edit/delete a complete menu!

We here at Lucius HQ always customize this per role, so the admin menu becomes more usabilicious. Your customer get's more statisfied and your company get's less helpdesk-calls :-)

How to set it up

  • We create an extra permission with hook_perm(), so website administrator can configure what role can have your custom access
  • We use hook_menu_alter() (since Drupal 6 in API) to check user's permission and if needed: change the default access

The Allmighty code

* Implementation of hook_perm().
function YOURMODULE_perm() {
  return array('Allow access to administration items');

* Implementation of hook_menu_alter().
* In this example: restrict access to
* + site settings section
* + node settings
function YOURMODULE_menu_alter(&$items) {
  $items['admin/settings']['access callback'] = '_YOURMODULE_checkperm';
  $items['admin/content/node-settings']['access callback'] = '_YOURMODULE_checkperm';

* Private function to check if logged in user has correct perms to access the menu item
function _YOURMODULE_checkperm(){
  return user_access('Allow access to administration items');

Extensively test your code

Since we are working with access control it is very important to test your scripts thoroughly. So be very careful with building custom scripts like this, if you don't know exactly what you are doing.

Feedback, Questions about access restriction?

Or maybe you know a nice module that does the trick...
Please hit me on Twitter for all your feedback, and any other issue!


Nóg meer
kennis nodig?

Check ons ons blog archief >