I understand that subgroups are basically groups that have some sort of subgroup designation.

But, what about a "Create Subgroup" link? Is this even possible since there is no "subgroup" content type?

What I'm thinking, specifically, is Group Menu link titled "Create Subgroup" (requiring a "create subgroup" permission) that would create a subgroup of the group you are currently in. With my og user roles module, one could then give a user the ability to create subgroups within a particular group.

Just an idea that would be really cool. I guess the issues are:

a) How to get a create content link on navigation menu for subgroups when subgroups isn't a content type, and:
b) How to create a permission to access this link.
c) How to make the link actually pull up a form that will create a group tagged as a subgroup of the current group?

Sound like a good idea? Possible?

Comments

somebodysysop’s picture

Actually, I sat down and figured out mostly everything.

Using hook_node_info I can actually create a "Subgroup" node type.
Using hook_perm I can define the permission to "create" this node type.
Using hook_access I actually get a "Create Subgroup" option to appear on the group menu.

Now, I just need to figure out how (when clicking on this link) to call up a group node creation form that forces a particular group (the current group context, also supplied in the link url) as the parent group.

Anyone know how to do this?

somebodysysop’s picture

I'm thisclose. I figured out that I could use hook_nodeapi('submit') to process the new group node just before it is saved to the database.

All I have to do is enter a record into og_ancestry that says that the group I am saving is a subgroup. I've created code to do this, and everything works except the db_query to save the og_ancestry record. I see the correct data from all the watchdogs (I've removed them here to make the code cleaner), but db_query just won't execute. Can anybody tell me why?

    case "submit";

		// Create a subgroup record for this group

		// 'ognodeadd' is my node add callback, so I know if this node is a group and 
		// here, then we need to process it as a subgroup
        // URL looks like this: mysite.com/node/ognodeadd?type=group&gids[]=29

		if ($node->type == 'group' && arg(1) == 'ognodeadd') { 

			if (!$node->nid) node_save($node); // gotta save node to get an nid

			$gids = $_GET['gids'];
			$gid = $gids[0]; // the parent group 
			$subgroup = $node->nid; // the subgroup group I am creating
			$sql = 'INSERT INTO {og_ancestry} (nid,group_nid,is_public) VALUES (%d,%d,0)';
			db_query($sql, $subgroup, $gid);		
		}

      break;
somebodysysop’s picture

Status: Active » Fixed

Whoops. Sorry.

Placed the nodeapi code under case 'insert', and it works perfectly.

I now have a mechanism working in my og user roles module where I get a

"Create subgroup"

link on my OG group menu (if, of course, I have the correct permission). When I click on this link to create a subgroup, I get a node type group submission page. When I submit the page, the group is tagged as a subgroup of the group from which I clicked on "Create subgroup".

Cool!

Anonymous’s picture

Status: Fixed » Closed (fixed)
csc4’s picture

Status: Closed (fixed) » Active

I'm not quite clear why this was closed? Is this feature in 5.x-2.0 as I can't seem to find it.

I'm looking for something similar to this - I wanted to let users create groups but force the parent to a value and I think this is probably the way to do it? or is there a better way?

somebodysysop’s picture

Creating subgroups under groups is a feature I implemented on og_user_roles: http://drupal.org/project/og_user_roles

ezra-g’s picture

Project: Subgroups for Organic groups » Content Type Administration by Organic Group
Version: 5.x-2.0 » 5.x-1.5
Status: Active » Closed (duplicate)

Commits were made recently that will allow OG_Subgroups to accept a gids= query string when creating\editing a subgroups. As far as providing these links, I believe this is a feature for the OG Content Type administration by Organic Group module or something that could be achieved by submitting a patch to Organic Groups allowing the Group Details block to be more customizable so that it displays "Create [content type]" links only for the desired content types. If such a feature is accepted to either of those two modules, they could perform a module_exists() check and read the possible parent group node types set in og_subgroups. Please see my old feature request at #148462: Restrict Content Types by OG Type.