Ok, here's the deal. I'm working on a site (http://www2.euronv.nl) and I'm walking into a brick wall.
This is what I want:
On the menupanel I've made a new block called "Projects".
- In this block I want menu-items of Projectnames which are links to nodes that have public access, so everyone visiting the site can see what it's about and if it's interesting for them.
- Under these Projects menu-items I would like to have the names of Organisations which participate in those projects and link to a node especially created for that organisation so it will only be accessible for those who are logged in with a username that belongs to a role with the same name as the Organisations name.
- Now every project of an organisation will have Projectphases (about 17 phases) so under the Organisation menu-items I would like other menu-item of Projectphases which link to nodes, where every node is a projectphase.
So the menublock Projects would like something like this:
- Carlease (Project, links to public node)
+- Dell (Organisation, links to node with access for role 'Dell')
-+- Projectphase1 (links to node with access for role 'Dell')
-+- Projectphase2 (links to node with access for role 'Dell')
-+- Projectphase3 (links to node with access for role 'Dell')
+- Compaq (Organisation, links to node with access for role 'Compaq')
-+- Projectphase1 (links to node with access for role 'Compaq')
-+- Projectphase2 (links to node with access for role 'Compaq')
So, I can do this. No problem. However the problem is that I don't want the Organisation and Projectphase menu-items to show in the block publicly. So what I'm trying to say is: The menu-items should have the same access rights as the nodes they are linking to and schould not be visible for those not having the correct access rights.
Is there a solution to my quest or is it technically impossible to do so?
Maybe there is a completely different way of getting to the same result that I overlooked but at this point I'm not getting any further. Please help.
Comments
Never tried this but....
Would it be possible to do what you want by setting up the menu on the basis of a taxonomy and then using Taxonomy Access Control? I've never tried to do this, but it sounds as if that might do the trick. Be interested if it works.
Unfortunately not...
Nope, I've already tried it.
It only sets the access-rights for nodes within a certain taxonomy (term) and not for the menu-items, kind of the same as the node_privacy_byrole module.
It would be possible to write a module to do that
Instead of using the menu module to generate the menu you could use a custom module to do what you want (you could also modify the menu module).
The difference from the existing menu module is it would allow you to limit which role(s) can view the entry and apoun generating the menu, check the users(s) roles against the list.
Customise menu.module...
And if I would do so by modifying the standard menu.module, any idea how to begin?
Is there an example of how to check accesrights or something like that?
I would start with access rules
In general terms you would be adding the abilty to menu items to set access rights. So the first step would be to define what sort of control you want. Since you are interested in roles it seems the choices would be public (not restrictions) or one or more roles.
So I would add a way to select one or more roles to the page that allows editing a menu item (could either use radio buttons to specify public/restricted or assume public if no roles are checked).
You then need a new column to story the 'roles'
I would also add a column to the main page for menus showing access rights.
Then in the code that produces the menu you would need to add a check to see if the current user can view the menu item (access may also be restricted by the module that produced the item)
A more general scheme would be to make an api that lets a seperate module determine if the menu item should be displayed.
Have you looked in the handbook
http://drupal.org/node/21867
Don't know if any of these snippets help you exactly.
*I* would write a custom module that implements hook_block to handle the logic of what gets displayed and when.
andre
Looking good...
I think I can work with this, tnx.
I'm also thinking maybe there is a way to make this work inside the menu_otf (menu on the fly) module.
Using that module you can make a menu_item "on the fly" when creating a node. This menu_item is directly inserted in a block on the position you like and links to the node created. Together with the node_privacy_byrole module and something like one of those php snippets, would it be possible to set the access rights for the node ánd the menu_item at the same time?
Different approach
I was trying to understand the block.module and the menu.module and I looked at a lot of PHP snippets.
But, after a while someone pointed out to me a different approach would come in much better.
This is what I did:
First I installed the following modules:
- Menu on the Fly (menu_otf)
- Node_privacy_byrole
This gives you the abilities to set access rights for nodes and to create a new menu-link for a node upon creating the node.
Then I used a patched block.module which gives you the ability to hide/show blocks for certain roles.
Patched block.module: http://drupal.org/node/49154
So you just create a new menu, then make the menu visible (administer->blocks) and then you set the access rights for the block.
Now when you create a new node, you set the access rights immediately with node_privacy_byrole and insert a new menu-item in the correct menu/block with menu_otf.
Works fine for me on Drupal 4.6.x but it should also work similar on 4.7
Greets, Flow
Partial solution
Have a look at http://drupal.org/node/57406 - the patch that I've developed will make all custom menu items display, ONLY if node_access determines that they should be displayed. However, the patch as it is now still needs work - I'd prefer to fix the underlying problem with the menu system, than to have this hack in node.module.
Jeremy Epstein - GreenAsh
Jeremy Epstein - GreenAsh