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 8073675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:24:26+00:00 2026-06-05T14:24:26+00:00

I can’t seem to figure out how to implement hook_menu_alter() to control access to

  • 0

I can’t seem to figure out how to implement hook_menu_alter() to control access to a node. I’ve started with a bare Drupal 7 install, created two nodes, and created a module with only this code:

function mymodule_menu_alter(&$items){
    $items['node/2']['access callback'] = TRUE;
}

This should simulate an actual callback function returning TRUE, which is where I started off. But I’m trying to show the simplest possible case, here.

If I set the access callback to “FALSE”, it works as expected: I get “access denied” on node/2. But if I set it to TRUE, shouldn’t I just get normal access to the node? Instead, when I go to node/2, I get a page similar to (but not exactly the same as) the default front page: a list of node teasers (In this case, showing the two nodes I created).

I have cleared the cache (because I know hook_menu_alter() isn’t called on every page view, but IS when the cache is cleared). I’ve also rebuilt permissions, to no avail. I’m sure I’m missing something dumb here, but I just can’t think of it.

I also tried it with an actual callback:

function mymodule_menu_alter(&$items){
    $items['node/2']['access callback'] = 'mymodule_access_check';
}
function mymodule_access_check() {
    return TRUE;
}
  • 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-06-05T14:24:28+00:00Added an answer on June 5, 2026 at 2:24 pm

    node/2 isn’t a menu item. The menu item for a node is actually node/%, so to change it’s callback you would have to do this:

    /**
     * Implements hook_menu_alter().
     */
    function mymodule_menu_alter(&$items) {
      $items['node/%node']['access callback'] = 'mymodule_access_check';
    }
    
    function mymodule_access_check($op, $node) {
      if ($node->nid == 2 && $some_condition) {
        return TRUE;
      }
      else {
        return FALSE;
      }
    }
    

    Note I added $op (which will be ‘view’) and $node (which will be loaded node object) to the functions args because they will be passed to it by ‘access arguments’, so in your mymodule_access_check function you have access to the node information.

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

Sidebar

Related Questions

Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can't figure out how to do this in a pretty way : I have
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
can any one tell me that how many users can access open cart site
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can someone access the database files and/or other files of my app stores in
Can anyone help me trying to find out why this doesn't work. The brushes
Can anyone give me syntax to alter an event which has been already created
Can I use something like winston npm in the underlying .meteor/local/build/server/node_modules? or even node-loggly
Can anyone let me know how can we change the value of kendo combobox

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.