6

How can I create an user account menu link that shows up only to registered/authenticated users in Drupal 8? I do not want anonymous users to see it.

For example, I want to have "add node" menu link.

( When anonymous users come to drupal sites they just see "login" on user account menu . When register users come to drupal sites they see "my account" and "logout" . I want show anonymous just "login" and for register users "my account","add node" and " logout . )

2 Answers 2

4

Long story short, you create 2 different Menu versions and give each version different visibility rules.

All you gotta do is configure your menu link block

enter image description here

Then in Roles, check mark ☑ Authenticated users and you may want to also ☑ Administrator

enter image description here

Now create another Menu (/admin/structure/menu) which does not have the "add node" link. Then go to blocks (/admin/structure/block) in Primary Menu (Assuming you're using Bartik, may have a different name if you're using a custom theme) click add, and add the Menu you just created and configure it.

This time for Roles, only check mark ☑ Anonymous

PS: In pages you can restrict so it only shows up in certain pages.

5
  • Thanks . But my question is not this . When anonymous users come to drupal sites they just see "login" on user account menu . When register users come to drupal sites they see "my account" and "logout" . I want show anonymous just "login" and for register users "my account","add node" and " logout .
    – user60258
    Jun 18, 2016 at 10:45
  • Edit your menu and add "Add Node"...
    – No Sssweat
    Jun 18, 2016 at 10:50
  • When I edit user account menu and "Add Node" , this menu link show to all users . ( Anonymous users : "login" "Add Node" ) ( Register users : "my account" "Add Node" "logout" )
    – user60258
    Jun 18, 2016 at 10:52
  • Did you configure the block like I mention in my answer? and just create a separate menu for anonymous...
    – No Sssweat
    Jun 18, 2016 at 10:55
  • Yes,thats work . But in "user account menu" when anonymous user come to site see only "login" and when register users come to site see "my account" and "logout" in user account menu . How can I d that just with 1 menu ?
    – user60258
    Jun 18, 2016 at 10:59
3

An "add node" menu link is only shown to users who have the permission to create such node. So if you give the permission to authenticated users, and not to anonymous users, you're done.

If you have other samples of links that have a related permission, then use a similar approach for that permission (don't grant it to anonymous users). If some link doesn't have such permission, then go for the approach described in the answer from @No Sssweat.

4
  • 1
    Interesting, I wasn't aware of this feature, I tried it and it worked. Is this a new feature of D8 or was this on D7 too?
    – No Sssweat
    Jun 18, 2016 at 8:40
  • 1
    @NoSssweat : really????? This is how it works already at least since D6 (no idea about D5 though). However, if such link does not have a related permission that goes with it, then I ALSO use your approach (also starting from D6). Jun 18, 2016 at 8:58
  • 1
    hmm some how I missed this, probably because I do not use the default Drupal Menus and create my own blocks as menus or use TBMegaMenu
    – No Sssweat
    Jun 18, 2016 at 9:15
  • 2
    @NoSssweat : why make it difficult, if you can do it using this ... Jun 18, 2016 at 9:22

Your Answer

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