2

I'd like to know how can I create a menu like so:

  • Menu X which appears when a Member X performs a login, for example when a simple user login, a Menu with 4 sections appears
  • but when a Member Y (for example a user as manager) performs a login, instead of Menu X (= simple user menu), this time a Menu Y (menu manager with 7 sections) appears.

any suggestions?

5
  • 1
    For your Kind Information, you should not combine two different subject in one question. And CSS question you should ask at stackoverflow.
    – CodeNext
    Jul 23, 2016 at 10:55
  • @CodeNext thank you , ok next time i will not combine two different subject in one question, for the css question i want to know how can i do it with drupal, where should i add the css style this is why i post it here
    – Imanelek
    Jul 23, 2016 at 11:00
  • thank you @NoSssweat but my question not about user/login page , my question is about how to get for example a menu x when member x login but when member y login he get menu y
    – Imanelek
    Jul 23, 2016 at 11:04
  • Are you using D7 or D8?
    – CodeNext
    Jul 23, 2016 at 11:13
  • i ' m using D7.
    – Imanelek
    Jul 23, 2016 at 11:16

2 Answers 2

4

This you can do easily with Roles for Menu module.

This module allows you to restrict access to menu items based on user roles. It is used when you don't want to copy your whole menu just because for one specific role you want to hide one menu item.

  1. Define the user role (in your case X and Y) in your site.
  2. Then as per user role you can set the menu items, so the menu will be automatically gets display based on Role.

Other similar module is Menu item visibility

This module exposes configurable and extendable visibility settings for menu links.

Both does pretty much similar activity.

Illustration for Menu item visibility module.

Steps:-

1. Module: Download and enable the module.

2. Creating User Role: Now, for example you want to set two user role X and Y. Hence, create by going at People/Permission/Roles -> add two user roles, like userX & userY as shown in following image. User Role Generation

3. Creating a User: Now, create two user, as shown in following image by going at People/ -> add new user, and give corresponding role which we created in step-2. You can see all specifications in the image. Adding user

4. Menu item creation: I have created a 7 Menuitems in the section Main menu by going as Structure/Menus/Main menu.

Main menu creation

Now, during the each Menu item creation, you will find the following option at the end of page, and from there selection, FOR WHICH USER YOU WANT TO SHOW THAT MENU-ITEM. Like in follwoing case we want to show Menuitem1 to userX and userY both.

Adding Menu item

I gave the user role visibility as below, because, I want to show first 4 item to userX Role and all other to userY Role.

Item               Roles Selection 
Menuitem1     userX     userY
Menuitem2     userX     userY
Menuitem3     userX     userY
Menuitem4     userX     userY
Menuitem5               userY
Menuitem6               userY
Menuitem7               userY

5. Test: Now, if you Login using userXexample(which has useX role) you will see only four items, and for userYexample(which has userY role) you will see 7 items.

enter image description here enter image description here

4
  • i activate the two modules for trying but i didn't get how to use them specially the menu item visibility
    – Imanelek
    Jul 23, 2016 at 16:41
  • 2
    Ok, I will post the image with directions in answer.
    – CodeNext
    Jul 23, 2016 at 16:43
  • Please have a look.
    – CodeNext
    Jul 23, 2016 at 17:40
  • 1
    It works ! many thanks !! the prob was in my path.
    – Imanelek
    Jul 23, 2016 at 21:02
1

Basically, you create 2 menus. One menu with the links for regular/authenticated users and another menu for Administrator with the admin links.

Then go to blocks (/admin/structure/block) and find the menu blocks and click configure. Then set the visivility to the approprate user roles.

enter image description here

3
  • Nothing happen, i try it many time link , link , then i don't find the configure block as yours link
    – Imanelek
    Jul 23, 2016 at 16:35
  • It should work. @No Sssweat's answer should work, it is also a perfect answer for achieving this. It is just other way, instead of playing at menu-item layer, Here, you are creating two entire different menu and you are applying User role to on entire menu. It should work for D7 as well as D8.
    – CodeNext
    Jul 23, 2016 at 18:31
  • 1
    No sssweat's and CodeNext thank you for taking the time to clarify!! Extremely helpful and I really appreciate it!
    – Imanelek
    Jul 23, 2016 at 21:04

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.