There should probably be an option to create a new forum when adding a new group.

I did this quickly for my needs in a custom module as so:

/**
 * Implements hook_node_insert().
 * Create a forum for each organic group created.
 */
function CUSTOM_node_insert($node) {
  if ($node->type == 'MY_GROUP_TYPE') {
    $term = new stdClass();
    $term->vid = MY_FORUM_VOCABULARY_ID;
    $term->name = $node->title . ' Forum';
    taxonomy_term_save($term);
    $values = array(
      'entity_type' => 'taxonomy_term',
      'entity' => $term->tid,
    );
    og_group('node', $node->nid, $values);
  }
}

Comments

melchior’s picture

Assigned: Unassigned » melchior

hey, thx for the code!

what's the best way to get the related tid on a node view? I tried the following code but it seems to be really inconvenient..

$query = new EntityFieldQuery();
		$query
		->entityCondition("entity_type", "og_membership", "=")
		->propertyCondition("gid", $node->nid, "=")
		->propertyCondition("entity_type", 'taxonomy_term', "=");
		$result = $query->execute();
		foreach ($result['og_membership'] as $item) {
			$id = $item->id;
		}
		
		$x = og_membership_load($id);
		$tid = $x->etid;
melchior’s picture

double post, sorry

jienckebd’s picture

In my case, this is the only taxonomy term I have associated with an organic group so this query works for me:

$tid = db_query("SELECT etid FROM {og_membership} WHERE gid = :nid AND entity_type = :type", array(':nid' => $node->nid, ':type' => 'taxonomy_term'))->fetchField();

I use it in hook_node_delete() along with the above code to delete taxonomy terms as my groups are deleted.

function mymodule_node_insert($node) {
  if ($node->type == 'company' || $node->type == 'group') {
    $term = new stdClass();
    $term->vid = 2;
    $term->name = $node->title . ' Forum';
    taxonomy_term_save($term);
    $values = array(
      'entity_type' => 'taxonomy_term',
      'entity' => $term->tid,
    );
    og_group('node', $node->nid, $values);
  }
}

function mymodule_node_delete($node) {
  if ($node->type == 'company' || $node->type == 'group') {
    $tid = db_query("SELECT etid FROM {og_membership} WHERE gid = :nid AND entity_type = :type", array(':nid' => $node->nid, ':type' => 'taxonomy_term'))->fetchField();
	taxonomy_term_delete($tid);
  }
}
vegantriathlete’s picture

Issue summary: View changes

I'm thinking it might make more sense to create a Container for the group instead of a forum.

Edit: Taking a closer look at the code it appears that it may be creating a container. Maybe the title of the issue just needs to be updated?

vegantriathlete’s picture

Status: Active » Closed (duplicate)

I do believe this will be addressed by #1535232: og forum administration