I have created a menu hook. I want to have the page available to anyone with either access level A or access level B. Both have been defined in hook_perm and hook_access.

But, I keep getting errors when I try to add the second access argument. Does anybody know if this is possible, and if it is, can you show me the syntax that I use to do it? Thank you.

Comments

gforce301’s picture

Well without an example of the code you are trying to use the best I have is this:

From here --> http://api.drupal.org/api/function/hook_menu/6

"access arguments": An array of arguments to pass to the access callback function. Integer values pass the corresponding URL component.

It says the arguments are an array. Sample code from that same page shows:

  $items['blog'] = array(
    'title' => 'blogs',
    'page callback' => 'blog_page',
    'access arguments' => array('access content'),
    'type' => MENU_SUGGESTED_ITEM,
  );

So to have 2 arguments it would look like this:

  $items['blog'] = array(
    'title' => 'blogs',
    'page callback' => 'blog_page',
    'access arguments' => array('access content', 'new argument'), // <-- notice the comma and the new argument added to the array.
    'type' => MENU_SUGGESTED_ITEM,
  );
jaypan’s picture

That's exactly what I was looking for. Thank you.

Contact me to contract me for D7 -> D10/11 migrations.

gforce301’s picture

Check out the API it will help you a lot.

advseb’s picture

Very strange, I exactly do it like you said and I get SQL errors. Here is the code hook_menu:

'access arguments' => array('create article content', 'create event content'),

And that are the SQL errors I get:

  • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 query: SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN () in /REMOVED/modules/user/user.module on line 502.
  • array_keys() [function.array-keys]: The first argument should be an array in /REMOVED/modules/user/user.module on line 502.
  • implode() [function.implode]: Invalid arguments passed in /REMOVED/includes/database.inc on line 241.
  • array_fill() [function.array-fill]: Number of elements must be positive in /REMOVED/includes/database.inc on line 241.

If I remove the second permission from the statement above, it works fine. Any ideas what is going wrong?

karenann’s picture

Found this thread while trying to do this. Wanted to post the solution for others who stumble on this.

Despite what's said above, you can't pass multiple access arguments like this. Also, don't bother trying array(array('perm 1', 'perm 2')).

By design, the access arguments's 2nd parameter is the $account param. That's why you can't pass 2 permissions that way.

You have to use 'access calback' instead and create a function that way.

Check out this post (it's right on): http://drupal.org/node/368584#comment-1236208

pieisgood’s picture

'access arguments' => array('edit own blah content, edit any blah content')

Notice that the two arguments are in the same quotes separated by a comma.

It works for me.

pieisgood’s picture

only works for admin

kcolbe’s picture

Don't use 'access arguments' => array('edit own blah content, edit any blah content'), that won't work unless you're the admin or you have a permission specifically defined in hook_perm called 'edit own blah content, edit any blah content'. The only way to accomplish this is to use your own access callback function then you can do whatever you want. karenann has the correct answer...