1
votes

Please bear with this Drupal API novice whilst I explain some background stuff!

I have been experimenting with the code below to create 2 separate responses when my users click on a custom node creation link. By default, a page opens that allows users to go through the usual steps in creating a node. What my module does is check if the user has specific permissions and either allow them to proceed in creating the node or throw up an access denied page.

function mymodule_menu_alter(&$items) {  
  $items["node/add/page/%"]['access callback'] = 'mymodule_access_callback';
}

function mymodule_access_callback(){
  if( user_access('open sesame') ){
    drupal_set_message("successfully intecepting new node creation");
    return true;
  }
  return false;
}

The node/add/page is blocked successfully but it does so in both cases. The if statement determines if the user has a certain permission and within it I added return true which resulted in the following error:

Fatal error: require_once() [function.require]: Failed opening required '/node.pages.inc' (include_path='.:') in /var/www/vhosts/mysite.co.uk/httpdocs/includes/menu.inc on line 347

As a novice, I am not sure what I need to do in order to avoid the access denied page for the right users.

1
To notice that Drupal doesn't define any menu callback for "node/add/page/%"; you are altering a menu item that doesn't exist, and you should not use hook_menu_alter() in this case.apaderno

1 Answers

0
votes

Try this:

function mymodule_menu_alter(&$items) {  
  $items["node/add/page/%"]['access callback'] = 'mymodule_access_callback';
  $items["node/add/page/%"]['file'] = drupal_get_path('module', 'node') . '/node.pages.inc';
}

EDIT

Try changing the second line above to this:

$items["node/add/page"]['file'] = drupal_get_path('module', 'node') . '/node.pages.inc';

It's an attempt to explicitly set the file path for the parent item of the path you're defining.

Also this might be a stupid thing to say but every time you make a change to hook_menu_alter() make sure you clear Drupal's caches so the changes are picked up.