1

We are working in Drupal 8 website and same user will have two different user profiles buyer and seller.

We want to show a user drop menu and when user click on "buy" link in drop down then main menu of the site would be changed as per "buyer" profile.

And if user click on "sell" link in drop down menu then main menu of the site would be changed as per "seller" profile.

2

The primary way to control visibility is through block visibility conditions.

There is no default condition available for what you are trying to achieve, so you have to implement your own.

See \Drupal\user\Plugin\Condition\UserRole, that does visibility based on the user role, what you want would be fairly similar, visibility based on a field, so like any other plugin, you can copy that into your module into the plugin namespace (\Drual\yourmodule\Plugin\Condition) and then adjust it to check the field instead and also offer the same select.

Then you place two blocks in the same region, each with a visibility configuration using your plugin. You need to think about what should happen when a user is not logged in, so maybe you have a default or hide both for anon users/users without a selection.

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.