0

In my module I have lots of different pages. All pages, as defined in mymodule_menu, access the same access callback function mymodule_user_access and perform different things based on the parameters passed. Now as far as I understand drupal calls that function for all the menu items that may be rendered on the page, which means that if there are 10 menu items visible, it will call the function for each one of them separately. What I would like to have is some way of seeing what path drupal is currently checking when the function is accessed. So if I have

$items['mymodule'] = array(
    //some stuff here
    'access callback' => 'mymodule_user_access',
    //some more stuff
);

$items['mymodule/path1'] = array(
    //some stuff here
    'access callback' => 'mymodule_user_access',
    //some more stuff
    'type' => MENU_LOCAL_ACTION,
);

$items['mymodule/path2'] = array(
    //some stuff here
    'access callback' => 'mymodule_user_access',
    //some more stuff
    'type' => MENU_LOCAL_ACTION,
);

which means that when I access mymodule page the mymodule_user_access page is accessed 3 times (for mymodule, mymodule/path1, mymodule/path2). What I would love to do is:

function mymodule_user_access() {
    drupal_set_message($path); //This should output 3 different messages: mymodule, mymodule/path1, mymodule/path2
}

Is it possible without explicitly sending the path as a parameter in access arguments?

UPD: I tried current_path but it returns the path I am trying to access. Same with arg()

0

Based on my research, I checked first the current_path() function and in it's code it gets the path by $_GET['q'] w/c indicates only getting the values fro the URL so this wouldn't work.

I also checked the access callback and access arguments' functionality and initially I noticed that access arguments are meant for the actual use that you are trying to bypass where links needs to be checked to let Drupal know if it will display a link. The only way is does this is by specifying the access arguments.

In my opinion, the access arguments array standardizes where the "access specifications" would come from like this menu's access specs are basing on the second and third arguments. So developers would know what they're dealing with by looking at the access arguments array and user the access callback just to do mostly logic.

I hope this could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.