1

how to unset admin menu links programmatically ?

I have created a module with this hook in it

function myModuleName_menu_link_alter(&$item)
{   

//  dpm($item['link_path']);
     if($item['link_path']=="/admin/config/people")
    {
     $item=FALSE;
    }
}

the link path

  "/admin/config/people"

is listed with dpm.

how can i remove it from the admin menu?

I have also tried with this hook

  function my module_menu_alter(&$items) {  

       // dpm($items['user/%user/cas']);
        unset($items['user/%user/cas']);
  }

2 Answers 2

2

hook_menu_alter is want you are looking for. The usage is exactly the same as your example, just don't forget to clear the caches afterwards.

Cheers!

2
  • well it does not work . could it be something to do with the translation? a different menu generated? i am using a french back office
    – Matoeil
    Commented Nov 11, 2014 at 9:50
  • 1
    I seriously doubt it. I successfully unset admin/dashboard and user/%user/edit if you worry for the wildcard operator. Should work with any other menu item. You did flush the cacehs right? Commented Nov 11, 2014 at 21:21
0

this is how i have done it

 /**
 * Implements hook_menu_alter.
 */

function people_manage_menu_alter(&$items) {
    $items['admin/people/create']['access callback'] = 'menu_people_access_callback';
   $items['admin/config/people/accounts']['access callback'] = 'menu_people_access_callback';
   $items['admin/config/user-interface']['access callback'] = 'menu_people_access_callback';


}


 function menu_people_access_callback($arg) {

       global $user;

        if(!in_array('administrator', $user->roles)) {  
           return false ;
         }
      else{
         return true;
       }

   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.