I want to hide the link to the forum from unauthenticated users.
All items in the 'Forum' category are on 'deny' and 'list' is checked off, so no unauthenticated user can access the content or list it.
Menu_per_role is installed (incl. patch) and works with other menu items. With this module, I restricted the menu item which points to 'forum' (or an URL alias which is associated with 'forum') to authenticated users and higher roles only. However, the link to the forum still shows up between the primary links for unauthenticated users, just with the difference that it leads to a page with the statement 'No Forum defined' (because of the access permissions ...). Rebuilding premissions does not help.
What am I missing? Thanks for any help,

Henning

Comments

masande’s picture

this may not be the answer you are looking for but a simple way to keep content, tabs, menu items, blocks etc. from view of anonymous users is to include the following statement:

<?php
global $user;
if ($user->uid) {
  print 'foo';
}
?>

this will only print 'foo' if a user is logged in. anonymous users won't see this item.

best of luck with your drupal project.

Mark Sanders
Q Collective

Mark Sanders
Q Collective

kriskd’s picture

I'm having the exact same problem (http://drupal.org/node/124381).

I'm not a coder, where would I put your suggested piece of code:

<?php
global $user;
if ($user->uid) {
  print 'foo';
}
?>
gpk’s picture

See http://drupal.org/node/180759#comment-281566 and my following comment. The problem seems to be to do with the fact that the menu item is disabled by default (it's a "suggested item"), and has to be enabled on the menu admin page (though the actual path /forum is always active). For normal menu items (that appear in the actual Nav menu structure ab initio) the problem apparently doesn't arise.

Have you "enabled" the "Forums" (-> /forum) menu item? Try it both enabled and disabled and see if menu_by_role works better in one state than the other.

gpk
----
www.alexoria.co.uk

gpk’s picture

I restricted the menu item which points to 'forum' (or an URL alias which is associated with 'forum')

I imagine you might need to apply the restriction to the underlying system path and not to the alias. Maybe you've tried that already?

gpk
----
www.alexoria.co.uk

daoane’s picture

Thanks for the help.
Mark: The code works fine. It allows me to show/hide items. In my case forum is part of the primary links. With the code I can show/hide all primary links. However, what I need is a way to hide one out of the primary links - or an explanation why menu per role does not work on the forum item. This takes me on to the suggestion of
gpk: I looked for the system path of forum - all I can tell from forum.module is that 'forum' is the system path - and that's where I applied the restrictions in menu per role. But maybe I misunderstood something with the pathes relationship to each other.

Henning

gpk’s picture

I can't think why menu_per_role wouldn't be working on just that one menu item: forum is indeed the system path. Without checking out what's happening in a PHP debugger, the only thing I can suggest is perhaps to build another custom menu that mirrors the primary links and output that in a block, or perhaps make a dynamic copy of the primary links menu (it's just an array) but remove the menu item corresponding to the forum.

You could also rebuild menu/permissions (if meny_by_role has that option) or just delete the menu cache?

gpk
----
www.alexoria.co.uk

daoane’s picture

I rebuilt permissions and cleared the cache many times during my trials. I checked several times that the Taxonomy access permissions are 'deny' and 'list' is disabled for unauthenticated users.
After your last post I created links in a separate menu. The result is exactly the same as with the primary links! Menus per role works fine as long as the link does not point to the forum. If it points to the forum the link will be visible for unauthenticated users although menus per role instructions tell drupal to hide it.

I had to put the site online with the issue "No forums defined". This has to be resolved later. But you can convince yourself at http://www.sddp.se
Thank you again for helping!

Henning

* reinstalling the menus per role and Taxonomy access modules did not help either

gpk’s picture

Possibly the forum menu has a high weight assigned to it, or is added to the menu data structure after menu_by_role has done its stuff, and is therefore not affected by it.

I created links in a separate menu. The result is exactly the same as with the primary links

This doesn't surprise me. What I was suggesting, as a workaround pro tem, is to "fix" the menu you create by hand so that the forum link is not present in it at all. Then depending on whether the user is logged in or not you show either the original primary links menu or your "fixed" version.

If you are displaying menus in blocks this is quite easy since on the block configuration page you can control which roles can see the block (i.e. have one block for anon, one for logged in users). For the primary links it's slightly more complex ... you could add a custom variable $primary_links_custom in phptemplate_variables() in template.php which is "hacked" as described above, according to whether the user is logged in or not, then in your page.tpl.php print $primary_links_custom instead of the usual $primary_links.

I realise this is all just workaround stuff but gives you a breathing space to find the real cause of the problem. Might be worth posting an issue to the menu_by_role project.

gpk
----
www.alexoria.co.uk

dwees’s picture

The problem is, the forum path in the forum module, which is defined by forum_menu has a type of MENU_SUGGESTED_ITEM instead of MENU_NORMAL_ITEM and as a result it's access isn't affected by menu_by_role. So the fix is to edit the forum module and change MENU_SUGGESTED_ITEM to MENU_NORMAL_ITEM, then navigate to admin/build/menus.

This may be a bug in menu.inc, but I'll doubt it will get fixed.

Dave

My site: http://www.unitorganizer.com/myblog

gpk’s picture

Hmmmm...

From menu.inc:

/**
 * Normal menu items show up in the menu tree and can be moved/hidden by
 * the administrator. Use this for most menu items. It is the default value if
 * no menu item type is specified.
 */
define('MENU_NORMAL_ITEM', MENU_VISIBLE_IN_TREE | MENU_VISIBLE_IN_BREADCRUMB | MENU_MODIFIABLE_BY_ADMIN);

...

/**
 * Modules may "suggest" menu items that the administrator may enable. They act
 * just as callbacks do until enabled, at which time they act like normal items.
 */
define('MENU_SUGGESTED_ITEM', MENU_MODIFIABLE_BY_ADMIN | MENU_VISIBLE_IN_BREADCRUMB);

Maybe the "visibility in tree" which is set (has to be) by the admin to make it appear in the first place overrides (happens later in the processing) than the menu_by_role restriction. This *could* be to do with module weights, or a bug in menu_by_role. Certainly worth searching the issues for menu_by_role, and raising one if appropriate.

Good luck!

gpk
----
www.alexoria.co.uk

dwees’s picture

Maybe it has to do with how we add it then? If it is a suggested item, then I should be able to find it disabled somewhere in one of the menus when I am administering them. What I was doing was adding the item directly to a different menu completely, which presumably means it has a different mid. Maybe what I should do is enable this item first, then add it somewhere else and fix it's access with menu_by_role.

Dave

My site: http://www.unitorganizer.com/myblog

elemental’s picture

Hey everyone,

I have been having the same issues. Here were my symptoms:

  • I did not use the Forums menu item that is disabled by default
  • I had created a new menu and a new menu item for the forums
  • The new menu item was using menu_by_role to restrict access
  • Whenever viewing the site as an Anonymous User, I would still see the Forums menu item

The resolution for this was to enable the default Forums menu item and set the menu_by_role access there as well. My guess is that the system ends up checking both access settings before deciding whether or not to display the menu item.

So, to summarize, in order to control access to forums using menu_by_role, you need to set identical accesses in both the new forums menu item as well as the default forums menu item.

Hope this helps!!!
Erik

wisemas’s picture

Hi all,

I am having the same issue for the site I'm currently creating. I want to hide the "forum" link for anonymous users.

I have tried to adjust the URL path so that it reads: www.example.com/forum instead of www.example.com/forum/1, but this leaves me with a message of "no forums defined".

I have also tried creating a custom block for anonymous users, but as I am using the greenNblack theme the primary links are contained within the header section.

I do not want to hack core as this will probably make the site unstable.

Any ideas or suggestions would be greatly appreciated.

Thanks in advance,

Wisemas

gpk’s picture

Suggest you use the same approach as in http://drupal.org/node/180759#comment-765239. The path "forum" by default usually brings up a listing of all available forums, or IIRC the message you have encountered ("no forums defined") if none is accessible to the current user i.e. the message may not be entirely accurate. Anyway, that's not so much the point ... suggest you set up a different menu item "forums" (note the "s") - which is not an existing Drupal path - and then proceed as per the other post.

gpk
----
www.alexoria.co.uk

wisemas’s picture

Hey all

I have looked at the menu per role module, and it requires me to patch a particular core file (menu.inc) which I don't want to do and with consultation with my boss, he doesn't want to do it either. Is there any other way of fixing this issue without needing to patch the core files?

Thanks in advance,

Wisemas

dwees’s picture

You can always create the code for your menu in Php and store this in a block, hiding/displaying the link to the forums as necessary. This has the problem that you will need to update your code every time you want to change the menu. :(

Other than this patch to core and the menu_by_role module, I'm not sure how else this can be done.

Dave

My site: http://www.unitorganizer.com/myblog

wisemas’s picture

I have fixed the issue by playing round with access rights, the ACL module, and it works great. The forum link cannot be seen unless you are logged into the site.

Wisemas

mfuggle’s picture

I have installed the ACL module and Forum Access and I can still see the forum menu as anonymous user even when there is no access to any forum for an anonymous user. If you could let me know your settings I would appreciate your help.

Cheers
Martin Fuggle

wisemas’s picture

I ended up disabling the primary links for unauthenticated users. Pretty much users have to log in to the site in order to view the content, and if the user is not logged in they cannot see anything. I created a sub-menu item with the login details, and then disabled all of the links to the content on the site.

I hope this helps? If at all?

Wisemas

lilon’s picture

I have primary links at the top as a menu with public access to all including anonymous, and navigation menu on the side as a menu for authenticated users only, which includes the forum menu item.
This way anonymous don't see the forum link.