I am using this very nice module for multi-site configuration. Since there are multiple sites I have used a menu to show the sites available, and the menu item path references the URL of the site. For example, http://example.com, http://sub1.example.com, http://sub2.example.com, http://sub1.anotherdomain.com
Now I am trying to find a way to make the menu items appear or disappear depending on access control rules. For example, some sites should be shown on the menu if anonymous, some should be shown so that only users logged in to site and member of a customer role should see the item.
I can then have many tabs configured, but only the tabs which are relevant will be shown to the user, either before they login or after they login, so that their roles are known.
I appreciate that a user can access the URL of the other site/domain in their browser, and only see content which they are allowed to see, but I wanted the menu at top of each site/domain page to show the tabs which are relevant to the user.
How can this be done ?
It seems to me that the problem is that when the Path in a menu item refers to the fully qualified URL instead of a relative path, the menu module has no way to check access to the content, and in our case the URL configured in Path will be a new domain home page, so access control in menu module might be hard unless it is possible to configure access control in the menu item itself, and make menu module use this to know when to show the item or not.
I would appreciate if anybody has any ideas on this. Perhaps there is a way to do this without making enhancements to the menu code ?
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 726460-alter.patch | 3 KB | agentrickard |
| #6 | 726460-alter.patch | 1.61 KB | agentrickard |
Comments
Comment #1
agentrickardWhy don't you use Domain Nav, which does some of this for you? You could then override its theme function to introduce more advanced logic.
In any event, I would start by studying how that module works.
Comment #2
TimAlsop commentedI appreciate your suggestion, but I am not clear why you think that Domain Nav will be of any help. I need access control checks for each domain/site, and Domain Nav does not have this - it just lists the domains available so I can click on them to visit the domain. This is the easy bit :-) which I have already done using a menu module.
Comment #3
agentrickardIf the menu items are nodes, they will be displayed according to access control rules.
If you are just linking to homepages, see how Domain Nav handles this in domain_nav_render(), where the access check is based on whether the domain is 'active' or 'inactive'.
You can extend this logic by using Domain Nav and using a theme override (or theme preprocess function, if available), to run additional logic checks on the domains, since the $options passed contain the domain_id that you can check against the user status.
Note that you can use hook_domainnav to add elements to the $options and then check those in your theme function.
Otherwise, you would write a variant of the module.
Comment #4
TimAlsop commentedMy current thinking is that we might be able to modify the Domain Nav module, so it takes configuration details from each domain (e.g. one or more roles) and uses these roles in conjunction with a roles access control module, to check if a user can access the domain, or not. It can then show/hide the domain based on the access, just like the module does at moment when domain is active or inactive (as you explained earlier). We can then create a theme for the Domain Nav links, so they look like we need them to, and show them on home page of each website. I assume we can change theme of the menu items shown by Domain Nav module ? Can you confirm ?
If we decided to develop a patch to an existing module, to provide this functionality do you think this would be accepted as a standard feature which others can benefit from ? We prefer this, compared to writing something which we then have to maintain and re-patch new versions of the module etc.
Comment #5
agentrickardA patch that allowed pluggable theme options to Domain Nav would be great. But module developers would still have to write custom themes.
I'm looking here, in the 'configure' $op for hook_block:
Or, maybe, a form hook to allow additional processing on the $options array before passing it to the render. Right now we have hook_domainnav(). Maybe we just need hook_domain_nav_alter() to pass the $options before they are handed to the theme layer.
With those two items, both really simple, you could do most anything you need.
Comment #6
agentrickardLike so. Apply from the root /domain directory.
Comment #7
TimAlsop commentedAt moment, when 'Menu-style tab links' is selected, the tabs are shown, but they are very basic, so I wondered if there is any css which could be changed to make these tabs look nicer ?
I am most interested in the access control changes, and whether the module developers would accept any such changes for inclusion in the standard module, or would we have to patch the module to support our access control needs and then maintain this patch if we upgrade to newer version of Domain Access in future ?
Comment #8
agentrickardCross-post!
The patch in #6 lets you substitute your own theme and/or alter the $options before they are themed. You put your logic in a custom module using hook_domain_nav_styles_alter() or hook_domain_nav_theme_alter().
The CSS is fairly standard Drupal Garland, so you should override it in your own theme css.
Comment #9
TimAlsop commentedSorry to ask so many questions, but I am not a developer, so some of what you describe does not make sense to me :-(
I am trying to find the best approach, and then I will pay a developer to work on the changes required.
If I understand you correctly, you are saying that if I apply the patch in #6, a new Drupal module can be developed which extends functionality in Domain Nav module, to allow both access control and new tab style (via theming). Is this correct ?
Comment #10
agentrickardYes. That is exactly correct. Using drupal_alter() will allow us to extend the module as you need without a) hacking it or b) putting use-case specific code into the main distribution.
Comment #11
agentrickardI'm going to add the $options alter hook. If you want to add a theme, use hook_form_alter().
Committed to 6.x and HEAD.
Comment #12
TimAlsop commentedIf I configure a block which contains Domain list navigator, I can select Menu-style tab links. The menu items are then shown as tabs, which is what I want. It also looks like these tabs are following the theme via CSS because if I change my theme, the tabs change as well. I am now wondering what advantage might exist for using your hook for theming the Domain Nav tabs ?
I assume your hook would be required to allow me to check if to show the domain in the menu or not ?
I need to know how to add a link into the Actions column when looking at a Domain list. The link would be called something like Roles and would allow the domain to have roles configured, which would then be used during the access checking to know if the tab should be shown or not.
Comment #13
agentrickardTo theme the tabs differently, you can use a standard Theme Override (search d.o for that).
This hook is expressly
to allow me to check if to show the domain in the menu or not?. Yes. The $options are passed to your function for modification. See API.php for documentation (hook_domain_nav_options_alter), which is misnamed in the doc as domain_nav_domain_nav_options_alter().Adding to the Domain list is hook_domainlinks(). See API.php for documentation.
Note: after items are fixed, you should open new issues, one per topic, please, unless the fix is broken.
Comment #14
TimAlsop commentedThankyou for your help. I asked what the theme was for because previously I was understanding you added it for theme purposes, but now it is clear that you added it for access control requirment only.
Regarding your comment about fixed/open issues... I opened this issue to get help, and this is why the subject starts with "How can I use...". When I have got the info I need to do what I wanted, then I can consider the issue closed. I might have few more questions over next few days, but if not I will close it so it is clear that I know how to do what I want.
Once again, I appreciate your help.
Comment #15
agentrickardI decided not to alter the theming aspect, since we already have tools for that (hook_form_alter() and theme overrides), so the access control issue was the only one left.
And you should get used to the fact that Drupal issue queues are public and that they are dynamic. This morphed into a feature request, since that is the best way to hit your original target.
Comment #17
baff commentedhttp://drupal.org/project/virtual_site