You are here

function og_membership_update_on_entity_presave in Organic groups 7

Update an existing group membership on entity presave.

See also

og_entity_presave().

File

./og.module, line 564
Enable users to create and manage groups with roles and permissions.

Code

function og_membership_update_on_entity_presave($values = array()) {

  // Update group membership entity.
  list($id) = entity_extract_ids($values['entity type'], $values['entity']);
  $group_membership = og_get_group_membership($values['gid'], $values['entity type'], $id);

  // Just make sure we the group membership.
  if (!$group_membership) {
    return;
  }

  // We know the state changed.
  // see og_entity_presave_group_audience_diff().
  $group_membership->state = $values['state'];
  $group_membership
    ->save();
}