Guest User

Untitled

a guest
Apr 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. Json :
  2. { "title":"Supervisor",
  3. "type":"group",
  4. "og_group_ref": { "und": [{ "target_id": "1921" }]},
  5. "field_records": { "und": [{ "value": "5" }]}
  6. }
  7.  
  8. /*
  9. * Implements hook_services_resources
  10. */
  11. function your_module_name_services_resources() {
  12. return array(
  13. 'add_user' => array(
  14. 'create' => array(
  15. 'help' => 'Add users to group',
  16. 'callback' => 'your_module_add_user_to_group',
  17. 'access callback' => TRUE,
  18. 'access arguments append' => TRUE,
  19. 'args' => array(
  20. array(
  21. 'name' => 'uid',
  22. 'type' => 'id',
  23. 'description' => 'The uid of the user to add in group',
  24. 'source' => array('data' => 'uid'),
  25. 'optional' => FALSE,
  26. ),
  27. ),
  28. ),
  29. ),
  30. );
  31. }
  32.  
  33. /*
  34. * Call back to add the user
  35. */
  36. function your_module_add_user_to_group($uid) {
  37. $user_account = user_load($uid);
  38. $og_values = array(
  39. 'entity_type' => 'user',
  40. 'entity' => $user_account,
  41. 'state' => OG_STATE_ACTIVE,
  42. );
  43. //This is will add the group to the user.
  44. og_group('node', $your_group_nid, $og_values);
  45. user_save($user_account);
  46. return success;
  47. }
Add Comment
Please, Sign In to add comment