Group tab in "audience" nodes is misleading
og_ui module generates a tab for each node of a given entity type:
foreach (og_get_all_group_entity() as $entity_type => $value) {
if ($entity_type == 'taxonomy_term') {
$path = 'taxonomy/term/%/group';
$argument = 2;
}
else {
$path = "$entity_type/%/group";
$argument = 1;
}
$items[$path] = array(
'title' => 'Group',
'page callback' => 'og_ui_group_admin_overview',
'page arguments' => array($entity_type, $argument),
'access callback' => 'og_ui_get_group_admin',
'access arguments' => array($entity_type, $argument),
'type' => MENU_LOCAL_TASK,
'file' => 'og_ui.admin.inc',
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
}
And in og_ui_group_admin_overview, the hook og_ui_get_group_adminis invoked so a bunch of links related with the group will be displayed, from permissions, to members, menus (depending on the number of og ecosystem modules) and there's no permission check on whether or not these links should be there.
These links throw an access denied, but it's a bit misleading for the user that doesn't necessarily know if the content being edited is a group or a regular node attached to a group.
I see two options:
- Provide a granular access per bundle of the entity types so the group menu is displayed only for groups. Probably the access callback of the items is
og_ui_get_group_adminshould be split so the callback returns just a simple TRUE/FALSE. - Leave the group link in both group and group content entities but add a #access parameter to the links in
og_ui_group_admin_overview
I've done something like this to remove the group tab from those nodes that don't really use it for my use case:
/**
* Implements hook_menu_alter().
*/
function hr_core_menu_alter(&$items) {
if (isset($items['node/%/group'])) {
$items['node/%/group']['access callback'] = 'hr_core_group_tab_access';
}
}
/**
* Access callback override for the group tab.
*/
function hr_core_group_tab_access($entity_type, $etid) {
$object = menu_get_object();
if (!og_is_group($entity_type, $object)) {
return FALSE;
}
// Fallback to the original callback.
return og_ui_get_group_admin($entity_type, $etid);
}