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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:56:16+00:00 2026-05-27T04:56:16+00:00

I am developing a new module and in my hook_menu_alter() I need to detect

  • 0

I am developing a new module and in my hook_menu_alter() I need to detect the node currently being viewed.

Instead of using arg(1) to fetch the the node id from the url, I discovered I can use
menu_get_object().

The following code works in my hook_init() but does not in hook_menu_alter():

$node = menu_get_object();
dpm($node);

Can anyone offer some insight into why that does not work and how to get the current node infomation in hook_menu_alter()?

Thanks.

  • 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-27T04:56:17+00:00Added an answer on May 27, 2026 at 4:56 am

    The output from hook_menu, hook_menu_alter etc. is cached so those functions will only be called when the caches are cleared, not for every page load. If you think about, if the menus were rebuilt on every page load the performance of the site would suffer considerably.

    As such, when hook_menu_alter is called (which won’t be from a node page), there’s no node for menu_get_object() to give you. The way to handle these things is in the page/access callback for the menu item:

    function mymodule_menu_alter(&$items) {
      $items['some/path']['page callback'] = 'mymodule_page_callback';
    }
    
    function mymodule_page_callback() {
      // This is a live page so menu_get_object() is now available
      $node = menu_get_object();
    }
    

    From your comment I think you’re trying to deny access to particular nodes based on some criteria. For this you’ll want to implement your own access callback for the already existing node/% menu path. Something like this:

    function mymodule_menu_alter(&$items) {
      $items['node/%node']['access callback'] = 'mymodule_access_callback';
    }
    
    function mymodule_access_callback($node) {
      if ($node->type == 'group') {
        if (some_function_that_determines_access($node)) {
          return TRUE;
        }
    
        return FALSE;
      }
    
      return node_access('view', $node);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing a new web application. This is the first time I'm using
We're currently developing a new piece of hand-held software. I cant discuss the nature
I am developing a Ecommerce website by using version Magento 1.6. I need to
I'm currently developing an ASP.NET Human Resources System. I'm using a layered architecture with
I'm currently developing a couple of modules to reuse code from my controllers on
Developing a new ROR3 website, I need to implement a sort of internal mail
I am new to Joomla. I am developing a dynamic module which will display
Developing a module for drupal and I need to pass/modify variables within functions. I
I am developing an android application(using Eclipse 3.5.2, Android 2.2) where i need to
While developing desktop applications using Perl Win32::GUI module in windows OS, a camel image

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.