* buildNavigationTree retreives items in order. We call this function to
* ensure that any items added by the hook are also in the correct order.
*/
- private static function orderByWeight(&$navigations) {
+ public static function orderByWeight(&$navigations) {
// sort each item in navigations by weight
usort($navigations, function($a, $b) {
}
/**
- * Get Menu name.
+ * Check permissions and format menu item as html.
*
* @param $value
* @param array $skipMenuItems
$name = $i18n->crm_translate($value['attributes']['label'], array('context' => 'menu'));
$url = CRM_Utils_Array::value('url', $value['attributes']);
- $permission = CRM_Utils_Array::value('permission', $value['attributes']);
- $operator = CRM_Utils_Array::value('operator', $value['attributes']);
$parentID = CRM_Utils_Array::value('parentID', $value['attributes']);
$navID = CRM_Utils_Array::value('navID', $value['attributes']);
$active = CRM_Utils_Array::value('active', $value['attributes']);
$target = CRM_Utils_Array::value('target', $value['attributes']);
- if (in_array($parentID, $skipMenuItems) || !$active) {
+ if (in_array($parentID, $skipMenuItems) || !$active || !self::checkPermission($value['attributes'])) {
$skipMenuItems[] = $navID;
return FALSE;
}
- $config = CRM_Core_Config::singleton();
-
$makeLink = FALSE;
if (!empty($url)) {
$url = self::makeFullyFormedUrl($url);
$makeLink = TRUE;
}
- static $allComponents;
- if (!$allComponents) {
- $allComponents = CRM_Core_Component::getNames();
+ if (!empty($value['attributes']['icon'])) {
+ $menuIcon = sprintf('<i class="%s"></i>', $value['attributes']['icon']);
+ $name = $menuIcon . $name;
}
- if (isset($permission) && $permission) {
- $permissions = explode(',', $permission);
+ if ($makeLink) {
+ $url = CRM_Utils_System::evalUrl($url);
+ if ($target) {
+ $name = "<a href=\"{$url}\" target=\"{$target}\">{$name}</a>";
+ }
+ else {
+ $name = "<a href=\"{$url}\">{$name}</a>";
+ }
+ }
+ return $name;
+ }
+
+ /**
+ * Check if a menu item should be visible based on permissions and component.
+ *
+ * @param $item
+ * @return bool
+ */
+ public static function checkPermission($item) {
+ if (!empty($item['permission'])) {
+ $permissions = explode(',', $item['permission']);
+ $operator = CRM_Utils_Array::value('operator', $item);
$hasPermission = FALSE;
foreach ($permissions as $key) {
$key = trim($key);
$componentName = CRM_Core_Permission::getComponentName($key);
if ($componentName) {
- if (!in_array($componentName, $config->enableComponents) ||
+ if (!in_array($componentName, CRM_Core_Config::singleton()->enableComponents) ||
!CRM_Core_Permission::check($key)
) {
$showItem = FALSE;
if ($operator == 'AND') {
- $skipMenuItems[] = $navID;
- return $showItem;
+ return FALSE;
}
}
else {
elseif (!CRM_Core_Permission::check($key)) {
$showItem = FALSE;
if ($operator == 'AND') {
- $skipMenuItems[] = $navID;
- return $showItem;
+ return FALSE;
}
}
else {
}
}
- if (!$showItem && !$hasPermission) {
- $skipMenuItems[] = $navID;
+ if (empty($showItem) && !$hasPermission) {
return FALSE;
}
}
-
- if (!empty($value['attributes']['icon'])) {
- $menuIcon = sprintf('<i class="%s"></i>', $value['attributes']['icon']);
- $name = $menuIcon . $name;
- }
-
- if ($makeLink) {
- $url = CRM_Utils_System::evalUrl($url);
- if ($target) {
- $name = "<a href=\"{$url}\" target=\"{$target}\">{$name}</a>";
- }
- else {
- $name = "<a href=\"{$url}\">{$name}</a>";
- }
- }
-
- return $name;
+ return TRUE;
}
/**
*
* @return string
*/
- private static function makeFullyFormedUrl($url) {
+ public static function makeFullyFormedUrl($url) {
if (self::isNotFullyFormedUrl($url)) {
//CRM-7656 --make sure to separate out url path from url params,
//as we'r going to validate url path across cross-site scripting.
'isFrontend' => $config->userFrameworkFrontend,
),
);
+ $contactID = CRM_Core_Session::getLoggedInContactID();
+ if ($contactID) {
+ $settings['config']['menuCacheCode'] = CRM_Core_BAO_Navigation::getCacheKey($contactID);
+ }
// Disable profile creation if user lacks permission
if (!CRM_Core_Permission::check('edit all contacts') && !CRM_Core_Permission::check('add contacts')) {
$settings['config']['entityRef']['contactCreate'] = FALSE;
),
'ajaxPopupsEnabled' => self::singleton()->ajaxPopupsEnabled,
'allowAlertAutodismissal' => (bool) Civi::settings()->get('allow_alert_autodismissal'),
+ 'resourceCacheCode' => self::singleton()->getCacheCode(),
);
print CRM_Core_Smarty::singleton()->fetchWith('CRM/common/l10n.js.tpl', $vars);
CRM_Utils_System::civiExit();