[Drupal] How to hide the node view from a particular node type in Drupal

| | 1 min read

In Drupal function hook_menu_alter() allows you to alter various properties of menu items. In your custom module, simply add the function. MODULENAME_callback_function will check the node type and hide the node view and edit from a particular node type. Here for our nodetype the hook_menu_alter() will call the callback function MODULENAME_callback_function, which will not show the view and edit tabs for our nodetype in Drupal.

The following function helps to implement

function MODULENAME_menu_alter(&$items) {
   // Set these tabs to callback function
 $items['node/%node'] = "MODULENAME_callback_function";  
}

function MODULENAME_callback_function($op, $node, $account=NULL) { 
 //code to hide the node view/edit link
  if (($node->type == 'nodetype') && ($user->uid != 1)) { 
   return FALSE;
  }
  else {
    return node_access($op, $node, $account);
  } 
}

We can also implement any required changes to node by following the same method.