Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7039577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:48:55+00:00 2026-05-28T01:48:55+00:00

I would like to limit the use of some url’s. Let’s say node/add and

  • 0

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).

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:48:56+00:00Added an answer on May 28, 2026 at 1:48 am

    The way to define a particular access function for a path is to set the access callback for the path’s menu item in hook_menu(). This is slightly different for existing paths, in that you need to implement hook_menu_alter() to edit the existing access callback for that path:

    function mymodule_menu_alter(&$items) {
      $items['node/add']['access callback'] = 'mymodule_node_add_access_callback';
    }
    
    function mymodule_node_add_access_callback() {
      // return TRUE to allow access, FALSE to deny
    }
    

    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 using hook_menu_alter() you can only change the access callback for all nodes.

    Fortunately Drupal has a hook_node_access hook to come to the rescue:

    function mymodule_node_access($node, $op, $account) {
      $restricted_nids = array(7, 10, 12);
    
      if (in_array($node->nid, $restricted_nids) && $op == 'view') {
        if ($some_condition_is_true) {
          return NODE_ACCESS_ALLOW;
        }
    
        return NODE_ACCESS_DENY;
      }
    
      return NODE_ACCESS_IGNORE;
    }
    

    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 the access callback should be a string and not an array as you currently have):

    $items['node/add/page']['access callback'] = '_mymodule_node_access';
    $items['node/add/page']['access arguments'] = array(0,2, $user);
    

    It’s also worth noting that the $user object 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use curl, on the command line, to grab a url,
I would like to limit the amount of physical memory a process can use
I would like to query some geo location points with morphia framework. I use
I would like to use the following example: <s:url var=remoteurl action=jsontable/> <sjg:grid id=gridtable caption=Customer
I would like some feedback on my first Python script that makes use of
I am trying to use Parallel::ForkManager to control some child processes. I would like
I would like to read some data from a GoogleFusion table and then use
I am using jQuery autocomplete and would like to limit the showing results only
I have a DTD and I would like to limit a few attribute properties'
I have a text field whose length I would like to limit at the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.