1

I need to show the user register link as a menu item in the account menu. I am able to add the link in the menu via links.menu.yml.

The menu links shows up for anonymous users as well as authenticated users but not for admin user role.

How can I hide the menu item for logged in users irrespective of user role?

3
  • have you created a custom menu link? Commented May 6, 2016 at 8:55
  • Look at RouteSubscriber, in 8 it is the new way to hook_menu_alter - api.drupal.org/api/drupal/…
    – Dylan
    Commented May 8, 2016 at 19:17
  • Using RouteSubscriber we can alter the visibility of a menu item but it doesn't effect the admin users. Commented May 9, 2016 at 7:46

5 Answers 5

2

Tried all the options to hide the menu item from authenticated users irrespective of the role, but admin always sees it. Did that using CSS and Menu Link Attributed module. Using the module I added a class to the menu link and then using the body class user-logged-in hid the menu item for logged in user.

I am still open to any other alternative and a better solution.

2

In case someone bumps here again, I found two ways it can be achieved within a theme without using any using module.

1) Using custom CSS:

.user-logged-in .menu.menu--account a[href="/user/register"] { display: none; }

2) Using custom JS:

$('.user-logged-in').find('.menu.menu--account a[href="/user/register"]').hide();

This is applicable only if you are customizing your theme in any way.

0

You can do this: group references in several menus: for registered - one for guests - another, etc. Then configure the units display, in which the menus are displayed on the page. The unit registered only show the registered menu.

0

Try the Menu Per Role Module. The new maintainer is trying to take over the drupal.org project but he has his code up on Github.

0

I can recommend the module Menu Item Role Access for this. It allows you to limit the access to a menu link by role. This can be configured for each menu link individually in its edit form. There you can also select it to be visible for Authenticated Users, which applies to all logged in users irrespective of other roles they may have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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