2
votes

I have a node type that should only be edited by users under certain circumstances that go beyond the permissions their role has. I am doing this in a custom module.

I would like to remove the ability to even see the edit tab, and not just add a validation function to the form that will alert the user after the form is submitted.

I need to add some sort of access function. Anyone know how to do this?

Thanks in advance.

--Update--

I now have 2 ways that should work.

1) Using hook_nodeapi:

function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch($op) {
    case 'prepare':
      if(!mymodule_access_function($node)) {
        $_REQUEST['destination'] = 'my_access_denied_page';
        // rest of function

2) I can insert a access callback function into the menu item using hook_menu_alter.

For my purposes, 2 makes more sense. I thought I would spell out the code for (1) though since that was the answer given on this page and it works.

2

2 Answers

3
votes

For the tabs visibility you can alter the themed output anywhere from a module hook to a theme template or css patch. Depending on the requirements for data visibility and performance issues some solutions are better than others. We need more details on what kind of processing you need.

For access, hook_nodeapi(), $op is 'prepare', run your custom code against $node at this point, and decide what you want to do (like redirect to another form if a requirement is not present, or to an access denied page).

Edit: Redirecting is usually done with $_REQUEST['destination'] = 'destination/alias' (does not break execution), sometimes drupal_goto('destination/alias') (breaks execution) is suitable but often it doesn't work. Please keep redirects tracked on your project, as with multiple logic conditions you may end up with unwanted and hard to debug behavior.

1
votes

Every content type has default permission settings in admin/user/permissions for creating,editing ,deleting node . You may assign to anonymous or authenticated users. If you want assign to group then create another role and assign permission as mentioned above.