3

I have a private website in which content can only be viewed by authenticated users. All I want is the login box for non authenticated users. I am using NodeAccess and also Rules module to do this. Seems to work fine with one exception. The pages which should only be visible after login show their links to the anonymous user on the Bartik theme main menu right on the home page. All menu items appear including those for pages specifically limited to administrator viewing. True, clicking on them merely brings up the login dialog box so the individual can't see the page, however, I don't want the menu itself to appear at all until the person is authenticated. How do I make the entire menu disappear if unautenticated? Thanks in advance.

1

The main menu in Bartik theme is being output directly (you can see it in 'themes/bartik/templates/page.tpl.php' - starts with <?php if ($main_menu): ?>). In order to hide the menu from anonymous users you could do the following:

<?php if ($logged_in): ?>
  <?php if ($main_menu): ?>
    // Code that prints the menu.
  <?php endif; ?>
<?php endif; ?>

Modifying core should be avoided though so the proper way to handle this would be to create a copy of the theme inside the 'sites/all/themes' folder with a different name. Then renaming necessary files, modifying the code and making your site use that theme instead of the core Bartik.

  • I appreciate greatly your explanation and work-around. Seems like a lot of work to do something as simple as turning off a menu for unauthenticated users. Is this a BUG in the Bartik core theme? It doesn't seem right to me, that there exists an option to make the main menu only visible to authenticated users but yet it will show up anyway for the unauthenticated ones. Although your coding solution might do it, I would prefer to find a non-coding solution to something that appears as a Bartik Core File BUG, unless indeed, it is a bug that needs fixing??? I will try your code as last resort. – Q Beat Jan 22 '12 at 1:03
  • I don't think it's a Bartik theme bug. The menu is output in a normal way - when you unpublish a specific node that appears in the menu it wont be displayed for example. Maybe the NodeAccess module should handle this, but isn't? Either way I don't have any other solutions to offer currently. – Madis Jan 22 '12 at 12:53
  • I really don't know where the bug is at, whether with the theme or core modules. I tested with a complete fresh installation without any added modules. What I found is that when the menu has permissions for only authenticated users only, the menu tabs still appear for unauthenticated users including those tabs that should be visible to selected roles only. I must not understand what is meant by the term visibility. I always thought that to be not visible, one would not be able to see it. I have implemented your simple code and it works great for my needs in this case. Thanks. – Q Beat Jan 24 '12 at 15:35
2

In case you are using D7, when you configure your menu block, you have a section called "visibility settings".There select the Roles tab and check the option "authenticated user" under "show block for specific roles". Then click save block.

  • I am using Drupal 7 and I found what you were referring to. I checked the "authenticated user" checkbox under the Visitiblity Settings of the Roles, however, it did nothing. The menu is still there on the home page for all anonymous users to see even thought it's visiblility setting is only for authenticated users. I tried creating a custom menu from scratch and using that instead of the built-in main menu, but the results were identical. – Q Beat Jan 21 '12 at 0:42
  • In that case, try using Nice Menus or DHTML menu and check if the problem still persists. – aerozeppelin Jan 23 '12 at 17:56
0

Beat, Just wondering, has anyone tried turning off the checkbox for Main Menu under: Appearance> Theme (eg. Bartik Settings)> Toggle Display> Remove checkbox from "main menu". that worked for me. Good luck.

  • Yes, your suggestion will turn off the main menu. However, if you read carefully the question at hand, you will see that the issue is not to turn off the menu, but to only hide it from unauthenticated users. If I do what you suggest, it would not be turned on for authenticated users even after they log in. I have not yet found a way to do it within Drupal or the theme, however, I have had success using the added php code as suggested previously. Unfortunately, each time I update the theme, I have to manually put the code back in. – Q Beat Feb 18 '14 at 14:33
-1

You can insert the Menu as a block and then use the Visibility > Roles settings to hide it for anonymous users.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.