Skip to content

Instantly share code, notes, and snippets.

@andydempster
Created October 15, 2015 16:26
Show Gist options
  • Save andydempster/61b120546797f099b360 to your computer and use it in GitHub Desktop.
Save andydempster/61b120546797f099b360 to your computer and use it in GitHub Desktop.
Some menu_alter code
/**
* Implements hook_menu_alter(&$item)
*
* Giant hack around a non-functioning permissions system - gets the users roles and checks to see if they
* can create content types - if so allow the menu link else disable it.
*/
//function olc_access_menu_alter(&$items) {
// // get the current user entity
// global $user;
// $account = $user;
// // now get the users roles as an array
// $acroles = $account->roles;
// // bail if admin
// if (in_array('administrator', $acroles)) {
// watchdog(WATCHDOG_NOTICE, 'user is admin - skipping menu shiz');
// return;
// }
//
// // get all content types as an array
// $content_types = node_type_get_types();
//
// // loop through and check permissions
// foreach ($acroles as $rolename) {
// // load up the role and get permissions array
// $role = user_role_load_by_name($rolename);
// $roles = array($role->rid => $role->name);
// $permsdata = user_role_permissions($roles);
// if (empty($permsdata)) {
// break;
// }
// // strip off the role_id that is returned
// $perms = reset($permsdata);
//
// // scan through each content type and check if can create
// foreach ($content_types as $content) {
// // if the permission exists - do nothing essentially
// if ($perms['create ' . $content . ' content']) {
// // do nothing
// }
// else {
//
// // no permissions for you!
// watchdog(WATCHDOG_NOTICE, 'no permissions on '.$content);
// $items['node/add/' . $content]['access callback'] = FALSE;
//
// }
// } // content loop
// } // role loop
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment