Question

I want to make a simple social network website using drupal 7. There will be a relationship type like 'friendship'. After a lot of Googling, I haven't found any way to forbid non-friend people from viewing a specific field. For example, there could be a field containing the user's phone number - I would want other users not to be able to see this field unless they are the user's friend. How do you do this? Are there any modules or anything else that could help me?

Was it helpful?

Solution

Your best friend would be your custom module that has hook_field_access() properly set up in it.

EXAMPLE:
function MYMODULE_field_access ($op, $field, $entity_type, $entity, $account) {
  switch ($entity->type) {
    case 'REFERENCED_NODE_TYPE_NAME': {
      ///DO YOUR STUFF HERE: SET A $VAR TO 'TRUE' OR 'FALSE' DEPENDING IF YOU WANT TO GIVE ACCESS.
    }
  }
  return $var;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top