0

This is a sort of sequel to my previous question How to hide specific fields and the according label in a view, based on field permissions?. One of the fields I'm displaying in my view is the standard User: Email field. I'd like to hide this field in my view except for the administrator and the user himself/herself.

How can I do that? I can't find a way to access the field with the Field Permissions module. If someone could show me a way to do that (my previous question is solved), this question would be solved.

Or is the Field Permissions module not suitable for this situation?

0

I think your issue here is a duplicate of this one: https://stackoverflow.com/questions/2727513/drupal-show-hide-fields-in-view

The two solutions are:

  • in the field template, display the content depending on the user role or
  • create two views displays, one for each of your user role
  • Mind that my problem hasn't only to do with user roles, but also with uid's, since the profile's "owner" should be able to see his/her e-mail field. – Jeroen Nov 27 '13 at 13:28
  • then the first solution (template) would be acceptable with something like: global $user; if($user->uid == $row->my_uid || in_array('my_role', $user->roles)) { print $my_field; } – Matt Nov 27 '13 at 13:43
0

I think Matt's answer is very close.

I would go the route of creating three views displays. The first display filters the content for Current User only and displays the email. The second view shows the email, and the display visibility permissions is set to administrators only. The third view hides the email field, but makes the view visible to anyone.

The fact is that Field Permissions has no effect on the email field, because it is unfortunately one of those "special case" field in Drupal (that existed long before the Field API did).

  • Thanks for your respons. I think your idea should work, but it looks quite a lot of work to me for such a little feature. I found a, in my opinion slightly easier, solution. You can read it underneath. – Jeroen Dec 2 '13 at 21:22
0

I found a solution for my problem! I installed the Email Field module and added a 'Emailadress' field to the user fields. I marked it as private with the Field Permissions module. Then, I created a rule that rewrites the 'Emailadress' field with the standard email after a user account has been created or updated. Finally, I added the 'Emailadress' field to my view.

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.