You are here

function og_entity_insert in Organic groups 7

Same name and namespace in other branches
  1. 8 og.module \og_entity_insert()
  2. 7.2 og.module \og_entity_insert()

Implements hook_entity_insert().

File

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

Code

function og_entity_insert($entity, $type) {
  if (!empty($entity->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE])) {

    // Create group membership for each group the new entity belongs to.
    list($id) = entity_extract_ids($type, $entity);
    foreach ($entity->{OG_AUDIENCE_FIELD}[LANGUAGE_NONE] as $item) {
      $item += array(
        'membership type' => '',
        'membership fields' => array(),
      );
      $group_membership = og_membership_create($item['gid'], $type, $id, array(
        'membership type' => $item['membership type'],
        'membership fields' => $item['membership fields'],
      ));
      $group_membership
        ->save();
    }
  }
}