0

I have privacy profile type and flags with checkbox like "Keep all my friends private" and "Keep all my videos and channels private".These are in my privacy settings profile.Now i want to allow or restrict the access based on my flagging (on/off checkbox) for the users.Here i have two content types videos & channels.By default other users can watch my videos & channels and i want to make it private when i click my checkbox on for "Keep all my videos and channels private" and once i uncheck this,it should become public.The same need to be done for "Keep all my friends private".I have used user relationship module for friends.How can i do this? Is it possible using php coding or is there any other solution.Please help. Thank you.

4
  • You'll need to use hooks. api.drupal.org/api/drupal/modules!node!node.api.php/function/…
    – SDMulroy
    Jul 3, 2014 at 10:40
  • Have tried using Rules?
    – sanzante
    Jul 3, 2014 at 10:41
  • using rules, you can play with the profile visibility with the user roles. If user click "Keep all my videos and channels private", add a role "Private" (for example), and then define permissions for this role. When unchecking "Keep all my videos and channels private" => remove role "Private".
    – Tritof
    Jul 3, 2014 at 11:26
  • Actually channel(node) page shouldnot be visible to users if the author has checked the profile flag "Keep all my channels private"(profile flag) in his privacy settings.I am tring with hooks but not getting how to check whether the flag "Keep all my channels private"(flag is of type profile) is flaged and based on that access is restricted.How to create a hook for this?
    – 12345
    Jul 3, 2014 at 11:49

1 Answer 1

1

Implement hook_node_access($node, $op, $account) and check whether the user has flagged his content to be private, if so then deny access.

function MYMODULE_node_access($node, $op, $account){
  global $user;

  if($node->uid != $user->uid && $node->type=='video' && $op=='view'){
     $entity_type = 'profile2';
     $profile = profile2_load_by_user($node->uid,'main');

     $flagging_data = flag_get_user_flags($entity_type, $profile->pid ,$node->uid);

     /************ UPDATED ****************/
     if(isset($flagging_data['channels'])){
          return NODE_ACCESS_DENY;
     }
  }
}
6
  • Thanks for your reply! But i am still not able to get specific flag as i have many flags in my privacy profile.So, how to get the specific profile flag (e.g."Keep all my videos and channels private") in the above code?
    – 12345
    Jul 4, 2014 at 11:11
  • The function will return all the flags associated with the entity for the user, so assuming you have two flags named videos,channels then if you want to check channels then see the updated answer.
    – msmani
    Jul 4, 2014 at 11:26
  • I have updated the changes but not able to save the module having the above code.I have enabled the module & when i try to save the same,getting whitescreen.How can i resolve this problem?
    – 12345
    Jul 4, 2014 at 12:06
  • Have you made any other changes, the code couldn't have caused the issue, check your PHP log.
    – msmani
    Jul 4, 2014 at 12:20
  • function videoprivacy_node_access($node, $op, $account){ global $user; if($node->uid != $user->uid && $node->type=='video' && $op=='view'){ $entity_type = 'profile2'; $profile = profile2_load_by_user($node->uid,'privacy'); $flagging_data = flag_get_user_flags($entity_type, $profile->pid, $node->uid); if(isset($flagging_data['my_videos_private'])){ return NODE_ACCESS_DENY; } } } This is the code which i have used in my module,but getting whitescreen while saving the module. How can i fix it?
    – 12345
    Jul 7, 2014 at 5:11

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.