/** * Inserts a navigation menu item at a given place in the hierarchy * * $menu - menu hierarchy * $path - path where insertion should happen (ie. Administer/System Settings) * $item - menu you need to insert (parent/child attributes will be filled for you) * $parentId - used internally to recurse in the menu structure */ function _iats_civix_insert_navigation_menu(&$menu, $path, $item, $parentId = NULL) { static $navId; // If we are done going down the path, insert menu if (empty($path)) { if (!$navId) { $navId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_navigation"); } $navId++; $menu[$navId] = array('attributes' => array_merge($item, array('label' => CRM_Utils_Array::value('name', $item), 'active' => 1, 'parentID' => $parentId, 'navID' => $navId))); return true; } else { // Find an recurse into the next level down $found = false; $path = explode('/', $path); $first = array_shift($path); foreach ($menu as $key => &$entry) { if ($entry['attributes']['name'] == $first) { if (!$entry['child']) { $entry['child'] = array(); } $found = _iats_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key); } } return $found; } }
function iats_civicrm_navigationMenu(&$navMenu) { $pages = array('admin_page' => array('label' => 'iATS Payments Admin', 'name' => 'iATS Payments Admin', 'url' => 'civicrm/iATSAdmin', 'parent' => array('Contributions'), 'permission' => 'access CiviContribute,administer CiviCRM', 'operator' => 'AND', 'separator' => NULL, 'active' => 1), 'settings_page' => array('label' => 'iATS Payments Settings', 'name' => 'iATS Payments Settings', 'url' => 'civicrm/admin/contribute/iatssettings', 'parent' => array('Administer', 'CiviContribute'), 'permission' => 'access CiviContribute,administer CiviCRM', 'operator' => 'AND', 'separator' => NULL, 'active' => 1)); foreach ($pages as $item) { // Check that our item doesn't already exist $menu_item_search = array('url' => $item['url']); $menu_items = array(); CRM_Core_BAO_Navigation::retrieve($menu_item_search, $menu_items); if (empty($menu_items)) { $path = implode('/', $item['parent']); unset($item['parent']); _iats_civix_insert_navigation_menu($navMenu, $path, $item); } } }