/** * Test that a navigation item can be retrieved by it's url. */ public function testGetNavItemByUrl() { $random_string = substr(sha1(rand()), 0, 7); $name = "Test Menu Link {$random_string}"; $url = "civicrm/test/{$random_string}"; $url_params = "reset=1"; $params = array('name' => $name, 'label' => ts($name), 'url' => "{$url}?{$url_params}", 'parent_id' => NULL, 'is_active' => TRUE, 'permission' => array('access CiviCRM')); CRM_Core_BAO_Navigation::add($params); $new_nav = CRM_Core_BAO_Navigation::getNavItemByUrl($url, $url_params); $this->assertObjectHasAttribute('id', $new_nav); $this->assertNotNull($new_nav->id); $new_nav->delete(); }
/** * Create or update a navigation item for a report instance. * * The function will check whether create or update is required. * * @param string $name * @param string $url * @param string $url_params * @param int $parent_id * @param string $permission * @param int $domain_id * * @param bool $onlyMatchParentID * If True then do not match with a url that has a different parent * (This is because for top level items there is a risk of 'stealing' rows that normally * live under 'Contact' and intentionally duplicate the report examples.) * * @return \CRM_Core_DAO_Navigation */ protected static function createOrUpdateReportNavItem($name, $url, $url_params, $parent_id, $permission, $domain_id, $onlyMatchParentID = FALSE, $useWildcard = TRUE) { $id = NULL; $existing_url_params = $useWildcard ? $url_params . '%' : $url_params; $existing_nav = CRM_Core_BAO_Navigation::getNavItemByUrl($url, $existing_url_params, $onlyMatchParentID ? $parent_id : NULL); if ($existing_nav) { $id = $existing_nav->id; } $nav = self::createReportNavItem($name, $url, $url_params, $parent_id, $permission, $id, $domain_id); return $nav; }