I would like to limit the use of some url’s. Let’s say node/add and node/7 (just random examples). I’m thinking the best way to do this is to use the user_access function.
But as we are used to it, the Drupal documentation doesn’t help much. When I just use the function, I get the message the function is already in use. So my best guess is to use this existing function with my own arguments in my custom function in my custom module.
But in this way I need to catch the page before loading it. Or I’m I missing something here?
EDIT:
I’ve set this
global $user;
$items['node/add/%']['access callback'] = array('_mymodule_node_access');
$items['node/add/%']['access arguments'] = array(0,2, $user);
But for some reason, Drupal isn’t picking up the % card for all types. It’s just working for one type (script). Other terms like page or fiche aren’t getting picked up… % is a Drupal wildcard right?
EDIT:
I just found out there are already some paths in the database. How can I overwrite them? What I need is one selector which can select all four content types (fiche, page, script and news-item).

The way to define a particular access function for a path is to set the
access callbackfor the path’s menu item inhook_menu(). This is slightly different for existing paths, in that you need to implementhook_menu_alter()to edit the existingaccess callbackfor that path:This gets a bit more fun when we’re talking about node pages as their menu items is defined using a wildcard
node/%. This means that usinghook_menu_alter()you can only change the access callback for all nodes.Fortunately Drupal has a
hook_node_accesshook to come to the rescue:Hope that helps
EDIT
If that all seems like a bit much hassle you might get some joy installing the Path Access module, I think it has the functionality you’re after.
ANOTHER EDIT
I think the reason overriding the wildcard isn’t working in this case is because the node module explicitly defines a path for each node type, e.g.
node/add/page,node/add/article, etc. Because Drupal will take an exact match (node/add/page) over a wildcard match (node/add/%) you’re actually overriding the wrong menu item.Try specifying the path explicitly in your
hook_menu_alter()function (note that theaccess callbackshould be a string and not an array as you currently have):It’s also worth noting that the
$userobject you’re passing will always be the user object of the logged in user who cleared Drupal’s caches (since menu items are rebuilt when the cache is rebuilt). If you’re looking to pass the current logged in user (i.e. the one logged in at the time the page is accessed) that’s a different thing altogether…I’d advise asking another question on it as it can be a tricky bugger and you want to get as much input as possible from people on here.