Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

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

share|improve this answer
1  
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
1  
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
add comment

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
1  
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
add comment

Your Answer

 
discard

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.