public function Group::addMember in Group 7
Add a user to a group.
If the user is anonymous or already a member, nothing changes.
Parameters
int $uid: The uid of the member.
array $values: (optional) Extra values to add to the GroupMembership entity, like the 'roles' property. You cannot overwrite the group id (gid) or user id (uid) with this method. Leave blank to make the user 'just a member'.
File
- classes/
group.inc, line 267 - Defines the Entity API class for groups.
Class
- Group
- Main class for groups.
Code
public function addMember($uid, array $values = array()) {
if ($uid != 0 && !$this
->getMember($uid)) {
$values = array(
'gid' => $this->gid,
'uid' => $uid,
) + $values;
$group_membership = entity_create('group_membership', $values);
$group_membership
->save();
}
}