From 70627370e647a689b52bcd048cb9fd8dc3bed979 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 12 Feb 2019 17:29:26 -0500 Subject: [PATCH] Migrate KAM smartmenus to core --- CRM/Admin/Form/Preferences/Display.php | 1 + CRM/Admin/Page/AJAX.php | 81 ++- CRM/Core/BAO/Navigation.php | 151 +++--- CRM/Core/Resources.php | 68 ++- .../plugins/function.crmNavigationMenu.php | 74 --- CRM/Core/xml/Menu/Admin.xml | 6 +- bower.json | 1 + css/civicrm.css | 4 +- css/civicrmNavigation.css | 181 ------- css/crm-menubar.css | 347 +++++++++++++ css/joomla.css | 23 - css/menubar-backdrop.css | 44 ++ css/menubar-drupal7.css | 115 +++++ css/menubar-drupal8.css | 55 ++ css/menubar-joomla.css | 29 ++ css/menubar-wordpress.css | 59 +++ extension-compatibility.json | 6 + js/crm.backdrop.js | 14 +- js/crm.drupal7.js | 5 - js/crm.drupal8.js | 40 +- js/crm.menubar.js | 479 ++++++++++++++++++ js/crm.wordpress.js | 16 + settings/Core.setting.php | 20 + .../CRM/Admin/Form/Preferences/Display.tpl | 7 + templates/CRM/common/CMSPrint.tpl | 2 - templates/CRM/common/accesskeys.hlp | 39 +- templates/CRM/common/accesskeys.tpl | 8 +- templates/CRM/common/joomla.tpl | 4 - templates/CRM/common/l10n.js.tpl | 2 + 29 files changed, 1422 insertions(+), 459 deletions(-) delete mode 100644 CRM/Core/Smarty/plugins/function.crmNavigationMenu.php delete mode 100644 css/civicrmNavigation.css create mode 100644 css/crm-menubar.css create mode 100644 css/menubar-backdrop.css create mode 100644 css/menubar-drupal7.css create mode 100644 css/menubar-drupal8.css create mode 100644 css/menubar-joomla.css create mode 100644 css/menubar-wordpress.css create mode 100644 js/crm.menubar.js diff --git a/CRM/Admin/Form/Preferences/Display.php b/CRM/Admin/Form/Preferences/Display.php index 2273f25b7fe8..ea13835328fb 100644 --- a/CRM/Admin/Form/Preferences/Display.php +++ b/CRM/Admin/Form/Preferences/Display.php @@ -51,6 +51,7 @@ class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences { 'ajaxPopupsEnabled' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'display_name_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'sort_name_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, + 'menubar_position' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, ); /** diff --git a/CRM/Admin/Page/AJAX.php b/CRM/Admin/Page/AJAX.php index 871b6d3e6d55..dc1f06589604 100644 --- a/CRM/Admin/Page/AJAX.php +++ b/CRM/Admin/Page/AJAX.php @@ -37,35 +37,76 @@ class CRM_Admin_Page_AJAX { /** - * CRM-12337 Output navigation menu as executable javascript. - * - * @see smarty_function_crmNavigationMenu + * Outputs menubar data (json format) for the current user. */ - public static function getNavigationMenu() { - $contactID = CRM_Core_Session::singleton()->get('userID'); - if ($contactID) { - CRM_Core_Page_AJAX::setJsHeaders(); - $smarty = CRM_Core_Smarty::singleton(); - $smarty->assign('quicksearchOptions', self::getSearchOptions()); - print $smarty->fetchWith('CRM/common/navigation.js.tpl', array( - 'navigation' => CRM_Core_BAO_Navigation::createNavigation(), - )); + public static function navMenu() { + if (CRM_Core_Session::getLoggedInContactID()) { + + $menu = CRM_Core_BAO_Navigation::buildNavigationTree(); + CRM_Core_BAO_Navigation::buildHomeMenu($menu); + CRM_Utils_Hook::navigationMenu($menu); + CRM_Core_BAO_Navigation::fixNavigationMenu($menu); + CRM_Core_BAO_Navigation::orderByWeight($menu); + CRM_Core_BAO_Navigation::filterByPermission($menu); + self::formatMenuItems($menu); + + $output = [ + 'menu' => $menu, + 'search' => CRM_Utils_Array::makeNonAssociative(self::getSearchOptions()), + ]; + // Encourage browsers to cache for a long time - 1 year + $ttl = 60 * 60 * 24 * 364; + CRM_Utils_System::setHttpHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', time() + $ttl)); + CRM_Utils_System::setHttpHeader('Cache-Control', "max-age=$ttl, public"); + CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); + print (json_encode($output)); } CRM_Utils_System::civiExit(); } + /** + * @param array $menu + */ + public static function formatMenuItems(&$menu) { + foreach ($menu as $key => &$item) { + $props = $item['attributes']; + unset($item['attributes']); + if (!empty($props['separator'])) { + $item['separator'] = ($props['separator'] == 1 ? 'bottom' : 'top'); + } + if (!empty($props['icon'])) { + $item['icon'] = $props['icon']; + } + if (!empty($props['attr'])) { + $item['attr'] = $props['attr']; + } + if (!empty($props['url'])) { + $item['url'] = CRM_Utils_System::evalUrl(CRM_Core_BAO_Navigation::makeFullyFormedUrl($props['url'])); + } + if (!empty($props['label'])) { + $item['label'] = ts($props['label'], ['context' => 'menu']); + } + $item['name'] = !empty($props['name']) ? $props['name'] : CRM_Utils_String::munge(CRM_Utils_Array::value('label', $props)); + if (!empty($item['child'])) { + self::formatMenuItems($item['child']); + } + } + $menu = array_values($menu); + } + public static function getSearchOptions() { - $searchOptions = Civi::settings()->get('quicksearch_options'); - $searchOptions[] = 'sort_name'; - $searchOptions = array_intersect_key(CRM_Core_SelectValues::quicksearchOptions(), array_flip($searchOptions)); - foreach ($searchOptions as $key => $label) { + $searchOptions = array_merge(['sort_name'], Civi::settings()->get('quicksearch_options')); + $labels = CRM_Core_SelectValues::quicksearchOptions(); + $result = []; + foreach ($searchOptions as $key) { + $label = $labels[$key]; if (strpos($key, 'custom_') === 0) { - unset($searchOptions[$key]); - $id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', substr($key, 7), 'id', 'name'); - $searchOptions["custom_$id"] = $label; + $key = 'custom_' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', substr($key, 7), 'id', 'name'); + $label = array_slice(explode(': ', $label, 2), -1); } + $result[$key] = $label; } - return $searchOptions; + return $result; } /** diff --git a/CRM/Core/BAO/Navigation.php b/CRM/Core/BAO/Navigation.php index 4006a300fef5..7e025198b67b 100644 --- a/CRM/Core/BAO/Navigation.php +++ b/CRM/Core/BAO/Navigation.php @@ -299,51 +299,6 @@ private static function buildTree($elements, $parentId = NULL) { return $branch; } - /** - * Build menu. - * - * @return string - */ - public static function buildNavigation() { - $navigations = self::buildNavigationTree(); - $navigationString = ''; - - // run the Navigation through a hook so users can modify it - CRM_Utils_Hook::navigationMenu($navigations); - self::fixNavigationMenu($navigations); - - // Hooks have added menu items in an arbitrary order. We need to order by - // weight again. I would put this function directly after - // CRM_Utils_Hook::navigationMenu but for some reason, fixNavigationMenu is - // moving items added by hooks on the end of the menu. Hence I do it - // afterwards - self::orderByWeight($navigations); - - //skip children menu item if user don't have access to parent menu item - $skipMenuItems = array(); - foreach ($navigations as $key => $value) { - // Home is a special case - if ($value['attributes']['name'] != 'Home') { - $name = self::getMenuName($value, $skipMenuItems); - if ($name) { - //separator before - if (isset($value['attributes']['separator']) && $value['attributes']['separator'] == 2) { - $navigationString .= ''; - } - $removeCharacters = array('/', '!', '&', '*', ' ', '(', ')', '.'); - $navigationString .= '