I am using Organic Groups and I have used this post to override the roles and permissions of OG Groups.
I need a hook to alter a button on my main menu that changes depending on whether the user is a member of a group (has any role in that group) or isn't a member of a group (and therefore hasn't got a role associated with his username)
The default button that always shows is 'add' when a user is associated with a group that button needs to be changed to 'remove' - with the according URL
I have created the following using this Drupal page:
function my_module_menu() {
$items['link'] = array(
'title callback' => 'change_link',
'title arguments' => array(1),
'page callback' => 'go_to’,
'page arguments' => array(1),
'access callback' => 'user_is_logged_in',
'menu_name' => 'main-menu',
);
return $items;
}
function change_link($gid) {
if(og_is_member('node', $gid)) {
return 'Remove';
}
else {
return 'Add';
}
}
function go_to($gid) {
if(og_is_member('node', $gid)) {
drupal_goto('www.mydomainurl.com/remove');
}
else {
drupal_goto('www.mydomainurl.com/add');
}
}
As well as fixing the above code - what does the array(1) do in page and title call back? --> I just copied them as is from the Drupal API page... (Does it look for the 'gid' in the last 2 functions?
UPDATE: (if any user of the site are part of any group - regardless of role - they will see only the 'remove' button if they aren't part of any group they will see the 'add' button.)
array(1)
search in the hook_menu's page for Callback Arguments it has a really good explanation.