function og_node_create_links in Organic groups 7
Same name and namespace in other branches
- 7.2 og.module \og_node_create_links()
Return a form element with crafted links to create nodes for a given group.
Parameters
$gid: The group ID.
$destination: Optional; The destiantion after a node is created. Defaults to the destination passed in the URL if exists, otherwise back to the current page.
$types: Optional; An array of type names. Restrict the created links to the given types.
1 call to og_node_create_links()
- og_node_create_links_content_type_render in plugins/
content_types/ node_create_links/ node_create_links.inc - Render callback.
File
- ./
og.module, line 3165 - Enable users to create and manage groups with roles and permissions.
Code
function og_node_create_links($gid, $destination = '', $types = NULL) {
$group = og_get_group('group', $gid);
if (!$group) {
return;
}
$types = isset($types) ? $types : array_keys(node_type_get_types());
foreach ($types as $type_name) {
if (og_is_group_content_type('node', $type_name) && node_access('create', $type_name)) {
$names[$type_name] = node_type_get_name($type_name);
}
}
if (empty($names)) {
return;
}
// Sort names.
asort($names);
// Build links.
$options = array(
'query' => array(
'gids_' . $group->entity_type . '[]' => $group->etid,
) + drupal_get_destination(),
);
$items = array();
foreach ($names as $type => $name) {
// theme_item_list's 'data' items isn't a render element, so use l().
// http://drupal.org/node/891112
$items[] = array(
'data' => l($name, 'node/add/' . str_replace('_', '-', $type), $options),
);
}
$element = array();
$element['og_node_create_links'] = array(
'#theme' => 'item_list',
'#items' => $items,
);
return $element;
}