Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By gibbo1715 on
Hi
I have a created a form that returns information to mymodule_item_form_page.
I have set up through the menu hook access permissions for the items that get returned but I would like to add the ability to allow additional users who would not normally have access to the item to be able to see it.
I have created a table that contains the id of the item and the uid from users,
does anyone have an example of how I can manage access permissions in this way please (i.e. group access + defined users
Thanks
Comments
In your hook_menu(), define a
In your hook_menu(), define a custom access callback:
Then do your tests in that access callback:
Thats great thanks
Thats great thanks
If I wanted to use this
If I wanted to use this function for multiple menu items (item/view, item/edit and item/delete) how would I wrap those in an if statement so I only need manage my permissions through the one function?
Many Thanks
You can pass a static value
You can pass a static value for the access argument to indicate what it is you're doing. Here is an example for a delete element:
Great, thanks, I ll see if I
Great, thanks, I ll see if I can get that working, assume if I had that the other way round %/delete it would be 'access arguments' => array('delete', 3),?
No, it would be array('delete
No, it would be array('delete', 1)
Sorry but don't think I quite
Sorry but don't think I quite understand this yet, Might be I'm not totally clear on how the menu system works yet
So if I wanted to do this from the following (As I'm running through hook_load()) how would I get the second argument?
Sorry, I don't understand the
Sorry, I don't understand the question, nor the reference to hook_load().
But the access arguments for both your paths would be:
I tried that but I get a
I tried that but I get a warning as follows
Warning: Missing argument 2 for my_access_callback() in my_access_callback() , I have cleared the cache
In my function I have
Hook_menu
Is that because I don't appear to be passing a second argument? works if I remove that
Are you showing your actual
Are you showing your actual code? I don't see how that error is possible based on the code you are showing. In your hook_menu(), your access arguments are here:
The first argument is 'view', and the second argument will be the result of meeting_load(). These become the arguments in my_access_callback():
The $op will be 'view', and the $id will be the result of meeting_load(). So I can't see how you would be getting that error, as both arguments are defined, and so you would never be missing argument 2.
This is my actual code so no
This is my actual code so no idea either, I'll keep playing and see if I can work it out,
I do run my database query in my meeting_load() function and that returns the database result which is working so I know something is returned, but it is the db object and not the id in the argument, maybe that's my issue?
Many Thanks
I'm thinking you must not
I'm thinking you must not have cleared your cache after changing your hook menu. That's the only way it could give you that error.
works now so maybe not, was sure i had..thanks
was sure i had..thanks