You are here

function node_gallery_api_entity_insert in Node Gallery 7

Implements hook_entity_insert().

File

./node_gallery_api.module, line 625
Node Gallery module.

Code

function node_gallery_api_entity_insert($entity, $type) {
  node_gallery_api_entity_update($entity, $type);
  if ($type == 'og_membership' && $entity->entity_type == 'node') {
    if (node_gallery_api_is_gallery($entity->etid)) {
      $bundle_type = db_select('node', 'n')
        ->fields('n', array(
        'type',
      ))
        ->condition('n.nid', $entity->etid)
        ->execute()
        ->fetchField();
      $relationship_type = node_gallery_api_get_relationship_type($bundle_type);
      if ($relationship_type->settings['og']['sync_items']) {
        $item_nids = node_gallery_api_get_item_nids($entity->etid, TRUE, FALSE);
        foreach ($item_nids as $nid) {
          $membership = og_membership_create($entity->group_type, $entity->gid, 'node', $nid, $entity->field_name);
          try {
            $membership
              ->save();
          } catch (OgException $ex) {

            // This membership already exists or is not group content type.
          }
        }
      }
    }
  }
}