You are here

function og_entity_presave in Organic groups 7

Implements hook_entity_presave().

File

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

Code

function og_entity_presave($entity, $type) {
  if ($diff = og_entity_presave_group_audience_diff($entity, $type)) {
    foreach (array(
      'insert',
      'update',
      'delete',
    ) as $op) {
      if (!empty($diff[$op])) {
        foreach ($diff[$op] as $item) {
          $item += array(
            'state' => OG_STATE_ACTIVE,
            'created' => time(),
            'membership type' => OG_MEMBERSHIP_TYPE_DEFAULT,
            'membership fields' => array(),
          );
          $values = array(
            'entity type' => $type,
            'entity' => $entity,
            // The group might be deleted already, and since we don't bulk
            // delete in such a case, we can't be sure it's there, so we just
            // pass the group ID.
            'gid' => $item['gid'],
            'state' => $item['state'],
            'membership type' => $item['membership type'],
            'membership fields' => $item['membership fields'],
            'created' => $item['created'],
          );
          call_user_func('og_membership_' . $op . '_on_entity_presave', $values);
        }
      }
    }
  }
}