Where do I override the access controls for the Edit tab of my custom module/node type (i.e. type = MENU_LOCAL_TASK, title = 'Edit')?

I did not put it inside my node_menu() so it is being auto-generated elsewhere. I have also played with user access values but can't seem to find the permission that only allows access by role. And the strange thing is that some roles can't see the Edit tab, but I can't control it.

(Note: I built my custom node by copying and editing an existing .module file, but now I can't remember which one I used.)

Comments

nofear’s picture

Use hook_perm to expose permissions then use hook_access to put some logic behind the access rules. It would look something like this.

//expose the permission which can be set on /admin/user/access for the different user roles
function yourmodulemname_perm(){
 return array('edit yournodetype');
}

//this is important if you want to make sure the user roles can not edit your node type, you should also have cases for 'create', 'update' and 'delete'
function yourmodulename_access($op, $node){
  
  switch($op){
    case 'edit':
      if(user_access('edit yournodetype')){
        return true;
      }
    default: break;
  }
   return false;
}

//Then in the hook_menu where you return the MENU_LOCAL_TASK item
function yourmodulename_menu(){
  $items[]=array('path'=>'blablabla', 'title'=>'blablabla', 'access'=>user_access('edit yournodetype'), 'type'=>'MENU_LOCAL_TASK);
  return $items;
}

http://humanopinion.org