Adding a custom node type to a groups block
Last modified: August 10, 2007 - 13:48
In my configuration of organic groups I have a custom content type 'group wiki' which is a landing page for that group's content. The content 'create' link is picked up fine by the default block, but it required a quick mod to get the actual item to appear dynamically in each group block.
First I modded the page theme to create the following
//Find a specific content type ('content_wiki_page')within the group
function theme_og_insert_groupwiki($gid, $type) {
$links = array();
if ($node->type = 'content_wiki_page') {
$sql = og_get_home_nodes_sql($type);
$result = pager_query(db_rewrite_sql($sql, 'n', 'nid', array('og_nid' => $gid)));
$wiki = db_fetch_object($result);
$links = l(t($wiki->title), "node/$wiki->nid");
}
return $links;
}Then added the call to og_og_create_links
// $group is an object containing the group node
function og_og_create_links($group) {
foreach (node_get_types() as $type => $name) {
$exempt = array_merge(variable_get('og_node_types', array('og')), variable_get('og_omitted', array()));
if (!in_array($type, $exempt) && node_access('create', $type)) {
$links[] = l(t('create %type', array('%type' => $name)), "node/add/$type", array('title' => t('Add a new %s in this group.', array('%s' => $name))), "gids[]=$group->nid");
}
}
// GET THE GROUP WIKI NODE INTO THE LINKS ARRAY
$group_node = og_get_group_context();
$gid = $group_node->nid;
$links[] = theme_og_insert_groupwiki($gid, 'content_group_wiki');
// END
return $links;
}A condition needs adding to remove the 'create' button one the node exists - but who knows? you may want more than one!
