Skip to content

Instantly share code, notes, and snippets.

@sumanthkumarc
Created February 20, 2017 11:03
Show Gist options
  • Select an option

  • Save sumanthkumarc/0adf6e6778709a6343e9288351967a4e to your computer and use it in GitHub Desktop.

Select an option

Save sumanthkumarc/0adf6e6778709a6343e9288351967a4e to your computer and use it in GitHub Desktop.
Adds a given user to given group as given role.
/**
* Adds a given user as member with given role to given group.
* @param GroupInterface $group
* Group Entity
* @param UserInterface $user
* An user account entity of type User Interface , not of Account Interface.
* @param array $role
* A group role in format : [GROUPTYPE]-[role] Ex: group-teacher
*/
function add_member_to_group(GroupInterface $group, UserInterface $user, $role) {
// For multiple roles, ['group_roles' => ['role1', 'role2']].
$roles = ['group_roles' => $role];
$group->addmember($user, $roles);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment