I have a role "editor" that is basically just that: it has all the content administration permission (but not content type administration). It has basically no other admin permissions.

I would like to use admin_menu for this role, in particular, I would like these users to be able to access the admin/content/node page through the content>content. To do this, I have to enable the "Use the administration pages and help" permission for that role. Unfortunately, that adds a whole bunch of other useless stuff: the structure menu is present, but empty, and the configuration menu is present, with all it's children, which are also all empty, and don't have content on their links. if I go to "configuration" (admin/config), there is no content there, except the link "hide description".

It would be ideal to hide all these empty items (and any parents that are empty). I don't know if this is best done as a patch to core, admin_menu, as core doesn't exhibit the problem so much (eg. it's probably there, but hidden).

CommentFileSizeAuthor
#3 admin_menu.permission-ux.3.patch2.68 KBsun

Comments

Courtney.B’s picture

Second this. Same issue as above. I have administer site configuration checked only for administrator but the menu item shows up for non-administrators with a bunch of links that don't really go anywhere.

Please let me know if you need more information or would like me to try something.

Thanks!

Courtney.B’s picture

Alright, so I came up with a quick and dirty way to hide the links that may be useless for certain roles. I doubt this is going to be the "recommended" way but if you need to hide them like... yesterday, you can do so this way as a stopgap.

Step One

Target specific role(s) by adding the viewer's role(s) to the body class. Add the following function to template.php located in sites/all/themes/yourtheme/template.php. The location may differ depending on your setup. For example, I'm using an Omega subtheme, so I've placed the function in the preprocess folder in the file preprocess-html.inc. I have not tested this for other themes so modification may be necessary. You may need to adjust the function name to be yourthemename_preprocess_html.

The purpose of adding the below function is to target a specific role. Check the source before adding the below because your theme may already place the role in the body class. This is so that when you hide a link, you do not hide it for everyone just for the roles where it serves no purpose.

function yourthemename_alpha_preprocess_html(&$variables) {
  global $user;
  foreach ($user->roles as $role_name) {
    $variables['attributes_array']['class'][] = 'role_' . strtr($role_name, ' ', '_');
  }
}

(Special thanks to BrockBoland and RLHawk who provided amazing assistance via IRC. I'm totally going to buy you two a beer at Drupalcon).

Step Two

In your theme's main stylesheet, you'll have to target each link using a CSS Attribute Selector. It is important to note that IE7 and IE8 only support attribute selectors if a !DOCTYPE is declared. IE6 and below do not support this CSS function.

Here is an example from my stylesheet, where I remove most of the links for the role "Adjunct Member":

.role_adjunct_member #admin-menu li a[href="/admin/config"],
.role_adjunct_member #admin-menu li a[href="/admin/structure"],
.role_adjunct_member #admin-menu li a[href="/admin/tasks"],
.role_adjunct_member #admin-menu li a[href="/admin/index"] {
	display: none;
}

And here is a breakdown of the CSS:

.role_ ==> the class placed into the body tag from the function in step one. The actual role name is appended after the underscore.
#admin-menu li a ==> targets a link
[href="/admin/xxxx"] ==> attribute selector to target a specific link

Special Note

The above directions are for hiding top-level links. If you need to target lower level links, you may need to wrastle with using extra li's like #admin-menu li li a.

Remember to set your permissions correctly before doing the above. This is not intended to supplant permissions but to hide links that were not hidden after the proper permissions are set.

sun’s picture

Status: Active » Needs review
StatusFileSize
new2.68 KB

The main complaint has been fixed via #871644: Hide links pointing to category/overview pages when empty

What remains, and perhaps I'm slightly abusing this issue, is to improve the user permission setup usability. Many users don't understand that two permissions are required to make the menu show up. (Frankly, I ran into the hiccup myself a couple of times...)

I've solved that with some fancy JS.

sun’s picture

Status: Needs review » Fixed

And since this is not Drupal core, the only way to get this actually tested is to commit it ;)

Thanks for reporting, reviewing, and testing! Committed to all branches.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

kaynen’s picture

#2 Above worked well for me. #3 seems like a reasonable solution, but there are too many changes that need to be made for RC1, which is the current codebase I'm using. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.