Closed (fixed)
Project:
OG User Roles
Version:
6.x-1.0
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
17 Dec 2008 at 05:13 UTC
Updated:
31 Dec 2008 at 05:20 UTC
Display the Create content link? and Remove the default Create links? are not working. Need to figure that out.
/**
* hook_og_create_links
*
* Modification as per: http://drupal.org/node/203875
* $group is an object containing the group node
*/
function og_user_roles_og_create_links($group) {
if (variable_get('og_user_roles_links_content_' . $group->nid, 0) == 1) {
$links[] = l(t('Create content'), "node/add", array('title' => t('Add new content in this group.')), "gids[]=$group->nid");
return $links;
}
}
/**
* hook_og_link_alter
*
* Modification as per: http://drupal.org/node/2517905
* Optionally remove create_ links.
*/
function og_user_roles_og_link_alter(&$links, $group_node) {
if (variable_get('og_user_roles_links_remove_' . $group_node->nid, 0) == 1) {
foreach($links as $key => $value) {
if(substr($key,0,7) == 'create_') {
unset($links["$key"]);
}
}
}
}
See: http://drupal.org/node/285474
Looks like I may have to use "drupal_alter('og_links', $links)"
This is the code referred to in og.module:
// Modify these links by reference. If you want control of the whole block, see og_block_details().
drupal_alter('og_links', $links, $node);
Found it. The code needs to look like this:
/**
* hook_og_create_links
*
* Modification as per: http://drupal.org/node/203875
* $group is an object containing the group node
*/
function og_user_roles_og_create_links($group) {
if (variable_get('og_user_roles_links_content_' . $group->nid, 0) == 1) {
$links[] = l(t('Create content'), "node/ognodeadd", array('title' => t('Add new content in this group.'), 'query' => 'gids[]=' . $group->nid));
return $links;
}
}
/**
* hook_og_link_alter
*
* Modification as per: http://drupal.org/node/2517905
* Optionally remove create_ links.
*/
function og_user_roles_og_links_alter(&$links, $group_node) {
if (variable_get('og_user_roles_links_remove_' . $group_node->nid, 0) == 1) {
foreach($links as $key => $value) {
if(substr($key,0,7) === 'create_') {
unset($links["$key"]);
}
}
}
}
Apparently, the l() function changed between versions 5.x and 6.x. Don't know why og_link_alter worked in 5.x but now requires og_links_alter in 6.x.
Modified code. Will include in next release.
Comments