Created
February 20, 2017 11:03
-
-
Save sumanthkumarc/0adf6e6778709a6343e9288351967a4e to your computer and use it in GitHub Desktop.
Adds a given user to given group as given role.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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