Easy Site Administration for Both Site Builders and Site Admins

By ryan | Thu, 06/25/2015 - 17:00

Coming up with a way to easily navigate and administer a Drupal site has always been a bit of a struggle. Usually, you’ve pleased the site builders and confused the normal site admins. Or pleased the site admins, but then caused the site builders to pull out their hair in frustration. We like to use admin_menu for site builders, and to use navbar as a nice and easy site admin toolbar. Admin_menu is great to give site builders quick access to almost every admin page there is. Navbar keeps things nice and simple – trying to avoid site admins getting overwhelmed with menu options, and potentially getting lost on their site. Each one works great for its target audience, but those target audiences aren’t the same, and most times, you’ll have both types of users actively using the site.

Here at Cheeky Monkey, we’ve found a way to keep both sides happy.

Our solution has been to combine the navbar module and the admin_menu module to play nice with each other. Normally, if you enabled both navbar and admin_menu, you’ll get them stepping on each other’s toes, and covering each other up, making neither one very usable. What we ended up doing was use admin_menu access priority. So if you have access to admin_menu, you only get the admin_menu. If you just have access to navbar, you only get the navbar.

You will need to create a custom Drupal module, or add the code to a pre-existing custom module to have all of the magic happen. Below are the functions we use to get the two modules to play nice with each other. As you will see, we make use of a few commonly used hooks, and a few lesser known ones as well to ensure when we want to use admin_menu, there are no lingering references to navbar adding some markup or causing javascript errors. The following example code assumes you’ve created a module called system_settings.

  1. /**
  2.  * Implements hook_page_alter().
  3.  */
  4. function system_settings_page_alter(&$vars) {
  5.   // Allow for both navbar and admin_menu to be enabled.
  6.   // Full admins get admin_menu, others get navbar.
  7.   if (isset($vars['page_top']['navbar'])) {
  8. 	// If the user can access the navbar, hide if they can see the admin menu.
  9. 	if (user_access('access navbar')) {
  10.       $vars['page_top']['navbar']['#access'] = !user_access('access administration menu');
  11. 	}
  12.   }
  13. }
  15. /**
  16.  * Implements hook_js_alter().
  17.  */
  18. function system_settings_js_alter(&$js) {
  19.   $javascript = &drupal_static('drupal_add_js', array());
  20.   // Drop a navbar added function if user isn't using navbar.
  21.   if (user_access('access administration menu')) {
  22. 	if (!empty($javascript['settings']['data'])) {
  23.   	foreach ($javascript['settings']['data'] as $key => $setting) {
  24.     	if (isset($setting['tableHeaderOffset']) && $setting['tableHeaderOffset'] == 'Drupal.navbar.height') {
  25.           unset($javascript['settings']['data'][$key]);
  26.     	}
  27.   	}
  28. 	}
  29.   }
  30. }
  32. /**
  33.  * Implements hook_module_implements_alter().
  34.  */
  35. function system_settings_module_implements_alter(&$implementations, $hook) {
  36.   if ($hook == 'js_alter') {
  37. 	// Move our implementation to the end of the list, so it fires last.
  38.     $group = $implementations['system_settings'];
  39.     unset($implementations['system_settings']);
  40.     $implementations['system_settings'] = $group;
  41.   }
  42. }


Adding this in has helped keep both our Monkeys and our clients quite happy, to have easy to use and easy to navigate sites when it comes to administration. And if you have a client site admin toolbar module you like to use, maybe this will give you some insight into how you might get it to play nice with admin_menu.

Need help with a big Drupal project? Our devs are available to help other agencies with everything from migration to maintenance. Call us!

More from author

Would you like to know more about what we do?

View Our Services

Have a look at some our client work

View Our Work

Learn more about Cheeky Monkey Media

About Us