I have a content type which has a required field containing some personal information like an email address. This field is not on the user entity - it is on an arbitrary content type.

What I need to do is conditionally hide or show this value based on whether the user consents for this information to be shown publicly.

I know that this can be done by creating a second boolean field ("show information" or similar) on the content type, and then overriding the theme template. The problem is that I am using a number of different view modes (via displaysuite) and do not want to have to override them all individually. I've tried calling hide() in hook_node_view with no success. I also can't just hide the value with jquery/css, since this field contains personal information and I can't output it at all if the user doesn't consent.

Is there a way to do this using display suite or a custom module? Is there a common solution to this that I'm overlooking?

2 Answers 2


Try User Field Privacy module. It exactly does, what you are looking out for.

  • 1
    Unfortunately, this hooks into the user entity. I need to do this on an arbitrary content type, not a user profile.
    – Zxaos
    Commented Dec 31, 2012 at 14:38
  • I was under the assumption that it was using user fields. Taking a look at the code may give you some insight.
    – Gokul N K
    Commented Dec 31, 2012 at 15:53
  • 1
    I'm using it as the basis for a small custom module, so it was helpful at least for some ideas. Thanks!
    – Zxaos
    Commented Dec 31, 2012 at 17:20

Implement hook_field_access($op, $field, $entity_type, $entity, $account).

To find out how the arguments are structured, var_export() them in your first implementation (or better yet, dpm() them).

  • 2
    Could you please explain how to implement it to get desired effect? One link answer would only help people who knows their way around field api already, and they are not likely to ask questions like this in the first place.
    – Mołot
    Commented Jun 5, 2013 at 14:20
  • Done that. Even though it's a common development strategy that is (IMHO) too trivial to mention.
    – Oswald
    Commented Jun 5, 2013 at 14:36

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.