Is it possible to have anonymous users (or more specifically, users without a 'member' role) be redirected from a specific menu item to an alternative node of my choosing, maybe using custom_url_rewrite_inbound?
开发者_运维技巧This would then enable me to have two versions of certain pages for members and non-members (it's a site specific thing!).
Cheers.
Using custom_url_rewrite_inbound()
for this would be somewhat similar to using a sledgehammer to adjust the angle of a crooked picture - can be done, but it is cumbersome and comes with the risk of causing some damage ;)
A better solution depends on what you want to achieve exactly, and how often (i.e. for how many nodes) you need to do it, so you should explain your scenario a bit more detailed. Some possible approaches include:
- 'Enrich' your nodes with data/fields for both versions, and adjust the actual output depending on user role
- If you use CCK, you could use the fields permission settings for this.
- You might also do some adjustments in the theme layer via custom node templates.
- Another approach would be via
hook_nodeapi()
(operation 'view') from a custom module, removing entries from the content array depending on user role.
- Provide explicit redirection to other nodes depending on user role (your explicit question)
- replace the standard node page callback via
hook_menu_alter()
with a custom one. Within that, you check the role. If it is ok, you just call the standard callback, else you issue adrupal_goto()
(based on some general logic, if possible). - If the 'special' cases are rare, you could do this via
hook_nodeapi()
as well, again reacting to operation 'view', but you'd need to make sure that you only do this for node page views, not if the node is just displayed as a teaser along with others. - Implement
hook_init()
in a custom module, check the path (arg()
or$_GET['q']
) and the role, issuedrupal_goto()
as needed. (Beware of cached pages - if you need to cover those, usehook_boot()
instead).
- replace the standard node page callback via
Etc. ... - I'm sure there are more options, so you might want to provide more details on your problem/goal/scenario to allow for a more precise suggestion.
You can create a custom menu handler for that link, and then in the function that runs that handler you could have something like
if (user->role == 'access granted') {
// do stuff
} else {
drupal_goto('anonymouspage');
}
精彩评论