I assume this is probably a simple thing.. but I sure as heck can't figure out how to do it.

I want to add a page with instructions for administering different parts of the site, and how to get to cpanel, that kind of thing. So, I created a page with this information, and added a menu item in the Navigation (admin) menu.

but.. when I log out.. there is the navigation menu with one item.. the link to the extra site administration page I created!!! Yikes!!!

how do I make the access so that this menu item only shows when the administrator is logged on?

Comments

jfall’s picture

I had exactly the same idea - document site maintenance on the site, for admin-eyes only.

But, as you found, I could not find a way to set access control on the menu item.

Here are two possible solutions:

1) Create a new content type for your site documentation. Set access rights to admin only. Menu items don't show for paths user has no rights to.
Consequence: not only is menu item hidden, but content is also access controlled.
Since I wanted to share my site design notes ( http://lasqueti.ca/books/design-notes ) with the community, this wasn't an option for me.

2) Create your menu item as a sub-menu of the Admin menu.
Admin menu only shows for admin - great.
But Drupal's menu module won't let you add menu items to the Admin menu through the user interface... bummer.
I needed to write some custom menu hooks anyhow, so I just added the design notes menu item in code. I used the book module to organize the notes, and the Book Navigation block to display a menu for the notes when they are being viewed (this goes away when you navigate away from the book).
This solution allows me to share the design notes book with others, provide a menu for navigating the book, but NOT have a link to the book anywhere visible on the site (except for admin).

Hope that helps.

ikati’s picture

I did add the menu item under "navigation" links - isn't that the admin menu? but.. it still showed when I logged out. so.. I don't know what I did wrong.

so, I think I will probably go with your first suggestion. I like being able to limit access of the page as well.

--------------------------

um.. ok, I created a new content type, but now I can't figure out how to restrict all access only to administrator. when I look at the access page, it gives me boxes for create/edit/delete content types.. but not access...

??

Lynne

Lynne

jfall’s picture

Sorry Lynne,
that was a bum steer - I could have sworn there was an access content permission for each content type - seems not.

The Navigation menu is not the admin menu - to add stuff to the admin menu, use the Menu settings on the node edit form (edit the node you want to hide, choose Navigation - Administration as the parent) - you can't do it directly through menu admin panel.

If you want to (or at least don't mind) restricting access to your admin notes, then just set the access rights on each node itself. You'll need to either create your own Admin role (and give it full permission) or install one of the contrib modules that automate creating the Admin role.

Good luck.

ikati’s picture

The Navigation menu is not the admin menu - to add stuff to the admin menu, use the Menu settings on the node edit form (edit the node you want to hide, choose Navigation - Administration as the parent) - you can't do it directly through menu admin panel.

that didn't work either (if I'm understanding you correctly). what I had to do was put admin in the path. then it worked, and would disappear for the public.

If you want to (or at least don't mind) restricting access to your admin notes, then just set the access rights on each node itself. You'll need to either create your own Admin role (and give it full permission) or install one of the contrib modules that automate creating the Admin role.

I'm getting confused.. I thought the nodes were the different content types.. page, blog, etc. Why would I have to create another Admin role (I am the admin).

Lynne

Lynne

jfall’s picture

what I had to do was put admin in the path

Oh yeah - forgot that bit! well done.

I thought the nodes were the different content types

Not quite. A node is a piece of content - one post - a blog article, a page, etc. A content type defines the characteristics of all nodes of that type. This is a really important Drupal concept.

Why would I have to create another Admin role

In Drupal 5.x (at least), for each node, you can restrict access by role, but since there is no "built-in" admin role, you can't restrict a node to just admin without creating that role. If you select no role, the node has no additional access restriction - so you have to pick some role - which role? the admin role! But there is no admin role by default, so you have to create one to get this.

geraldito’s picture

Maybe not a very efficient solution for your situation but for my case it was the easiest way to use a view with restricted access. I'm showing the administrator content which isn't published yet using a view and so restricted the access to admin role. Restricted views - and their related menu entries - show up only for users who have permissions to access them.

matt_c’s picture

If you have a lot of roles, and need to restrict access to a subset of roles, not just admin, then I suggest using the blocks access controls. I ended up making a new menu containing links that where restricted to specific roles, and displaying that menu as a block above the navigation menu. Then it is easy to apply access permissions to the block through the "configure" link on the block administration page. This saves installing any new modules.

gdoteof’s picture

another solution is to make a menu block that only displays (using php) with

global $user
if ($user->uid == 1) TRUE : FALSE;
rangi500’s picture

This is the approach I've gone with too - here's the exact snippet I'm using:

<?php
global $user;
return
$user->uid == 1;
?>
drupalshrek’s picture

This blocking with PHP looks like the sort of thing I want to do, but I cannot find where to put the proposed PHP code. When I look at the list of blocks (admin/build/block) and do "Configure" against the block I want to restrict, I only get the following options:

  • Block specific settings (title)
  • User specific visibility settings
  • Role specific visibility settings
  • Page specific visibility settings

None of these give me the option to add PHP code.

Please clarify!

drupalshrek
Please fill in my Learning a foreign language questionnaire if you have a moment.

dibyadel’s picture

Thanks a lot. It helped me a lot as I needed another menu for admin to put some customerised reports.
thanks again.

d dutta

D Dutta
New Delhi

Aljullu’s picture

I think the easiest way to solve that problem is using this module:
https://drupal.org/project/menu_item_visibility