Commit be43a8f8 authored by mattwire's avatar mattwire
Browse files

Don't build group menu items if there are no group admins

parent 2ae7bf50
......@@ -39,13 +39,6 @@ class CRM_Groupadmin_NavigationMenu {
$groupList[$groupAdminContact['group_id']] = 1;
}
// Get list of group name/title for all groups which have admins
$groups = civicrm_api3('Group', 'get', [
'return' => ['id,', 'name', 'title', 'group_type'],
'id' => ['IN' => array_keys($groupList)],
['options' => ['limit' => 0]],
])['values'];
try {
$rootMenuItem = civicrm_api3('Navigation', 'getsingle', [
'name' => 'groupadminmenu',
......@@ -66,29 +59,38 @@ class CRM_Groupadmin_NavigationMenu {
['options' => ['limit' => 0]]
])['values'];
foreach ($groups as $group) {
$newMenuItem = [
'is_active' => 1,
'permission' => "access GroupAdmin menu {$group['id']}",
'icon' => "crm-i fa-user",
'parent_id' => $rootMenuItem['id'],
];
$newMenuItem['name'] = "groupadminmenu_{$group['name']}";
$newMenuItem['label'] = $group['title'];
if (!empty($groupList)) {
// Get list of group name/title for all groups which have admins
$groups = civicrm_api3('Group', 'get', [
'return' => ['id,', 'name', 'title', 'group_type'],
'id' => ['IN' => array_keys($groupList)],
['options' => ['limit' => 0]],
])['values'];
$url = $this->getURL($group);
$urlParts = explode('?', $url);
if (isset($urlParts[1])) {
$urlParts[1] = str_replace('%%gid%%', $group['id'], $urlParts[1]);
}
$newMenuItem['url'] = CRM_Utils_System::url($urlParts[0], $urlParts[1] ?? []);
foreach ($existingMenuItems as $existingMenuItem) {
if ($newMenuItem['name'] === $existingMenuItem['name']) {
$newMenuItem['id'] = $existingMenuItem['id'];
break;
foreach ($groups as $group) {
$newMenuItem = [
'is_active' => 1,
'permission' => "access GroupAdmin menu {$group['id']}",
'icon' => "crm-i fa-user",
'parent_id' => $rootMenuItem['id'],
];
$newMenuItem['name'] = "groupadminmenu_{$group['name']}";
$newMenuItem['label'] = $group['title'];
$url = $this->getURL($group);
$urlParts = explode('?', $url);
if (isset($urlParts[1])) {
$urlParts[1] = str_replace('%%gid%%', $group['id'], $urlParts[1]);
}
$newMenuItem['url'] = CRM_Utils_System::url($urlParts[0], $urlParts[1] ?? []);
foreach ($existingMenuItems as $existingMenuItem) {
if ($newMenuItem['name'] === $existingMenuItem['name']) {
$newMenuItem['id'] = $existingMenuItem['id'];
break;
}
}
civicrm_api3('Navigation', 'create', $newMenuItem);
}
civicrm_api3('Navigation', 'create', $newMenuItem);
}
\CRM_Core_BAO_Navigation::resetNavigation(CRM_Core_Session::getLoggedInContactID());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment