3

I have many fields added for users. What I want is the following: If the logged in user has a role W and is viewing a user page that belongs to a user of role X then show field Y. Otherwise, field Y should not be visible.

I have tried using a a module named "Field Formatter Conditions" that supposedly has rules integrations and offers the Event: A field is being rendered and the Action: Hide a field. However, when I select the action to hide the field, There is nothing to be configured and I just get the save button.

Kindly suggest how I can accomplish the target and I prefer if the solution is based on rules.

1

2 Answers 2

1

You can use the Field Permissions as Pierre's answer said. You just need to change the role that can see that field.

In the page listing all the installed modules, click on Configure link shown for the Field Permissions module.

screenshot

The next page will show all the fields added to entities, their type, the entity to which they are added, the bundles for that entity which have that field, and a summary of the permissions for that field.
For the field that you want to change the permissions, click on the entity containing it, which is a link to another page. In your case, that link is labelled User, since the field is for the User entity.

screenshot

The link will take you to a form where you can change its permissions.
On Field visibility and permissions click on Custom permissions. On the View anyone's value for field Y row, select only the checkboxes for the admin and W roles.

screenshot

In this way, the field will be visible to the users with those roles, when they watch the account of other users.

0

I think you would come closer to an actual solution by using the Field Permissions module.

... allows site administrators to set field-level permissions to edit, view and create fields on any entity.

Not sure if it'd cover all your requirements, but it might be part of the solution to your puzzle. For sure you can use it to "Hide a field on a user profile if the logged in user has a specific role" (as in the title of your question).

If the logged in user has a role W and is viewing a user page that belongs to a user of role X then show field Y. Otherwise, field Y should not be visible.

That sounds like using Field Permissions to configure your field Y so that this field is shown to users with role W and hidden to users without role W. This probably does not take into account "... a user page that belongs to a user of role X...".

1
  • i am already using the field permissions module but it does not give me the flexibility to apply the condition listed above I want the user with role patient view a field called Doctor address when viewing a doctor user page. At the same time I dont want the Doctor address field to be visible to the user with role Patient when the user views his own profile Commented Feb 9, 2017 at 21:27

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.