Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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

share|improve this answer
Unfortunately, this hooks into the user entity. I need to do this on an arbitrary content type, not a user profile. – Zxaos Dec 31 '12 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 Dec 31 '12 at 15:53
I'm using it as the basis for a small custom module, so it was helpful at least for some ideas. Thanks! – Zxaos Dec 31 '12 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).

share|improve this answer
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 Jun 5 '13 at 14:20
Done that. Even though it's a common development strategy that is (IMHO) too trivial to mention. – Oswald Jun 5 '13 at 14:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.