From: Coleman Watts Date: Sun, 7 Apr 2019 15:13:47 +0000 (-0400) Subject: Use asset-builder to render menubar css X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1889d803c21e702dcf73d13072e3effa4b633358;p=civicrm-core.git Use asset-builder to render menubar css --- diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 4911057717..4c3fcd6ec1 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -24,6 +24,7 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ */ +use Civi\Core\Event\GenericHookEvent; /** * This class facilitates the loading of resources @@ -581,6 +582,7 @@ class CRM_Core_Resources { * @return CRM_Core_Resources */ public function addCoreResources($region = 'html-header') { + Civi::dispatcher()->addListener('hook_civicrm_buildAsset', [$this, 'renderMenubarStylesheet']); if (!isset($this->addedCoreResources[$region]) && !self::isAjaxMode()) { $this->addedCoreResources[$region] = TRUE; $config = CRM_Core_Config::singleton(); @@ -760,14 +762,10 @@ class CRM_Core_Resources { $position = Civi::settings()->get('menubar_position') ?: 'over-cms-menu'; } if ($position !== 'none') { - $cms = strtolower($config->userFramework); - $cms = $cms === 'drupal' ? 'drupal7' : $cms; $items[] = 'bower_components/smartmenus/dist/jquery.smartmenus.min.js'; $items[] = 'bower_components/smartmenus/dist/addons/keyboard/jquery.smartmenus.keyboard.min.js'; $items[] = 'js/crm.menubar.js'; - $items[] = 'bower_components/smartmenus/dist/css/sm-core-css.css'; - $items[] = 'css/crm-menubar.css'; - $items[] = "css/menubar-$cms.css"; + $items[] = Civi::service('asset_builder')->getUrl('crm-menubar.css'); $items[] = [ 'menubar' => [ 'position' => $position, @@ -825,6 +823,35 @@ class CRM_Core_Resources { return (strpos($url, 'civicrm/ajax') === 0) || (strpos($url, 'civicrm/angular') === 0); } + /** + * @param GenericHookEvent $e + * @see \CRM_Utils_Hook::buildAsset() + */ + public static function renderMenubarStylesheet(GenericHookEvent $e) { + if ($e->asset !== 'crm-menubar.css') { + return; + } + $e->mimeType = 'text/css'; + $e->content = ''; + $config = CRM_Core_Config::singleton(); + $cms = strtolower($config->userFramework); + $cms = $cms === 'drupal' ? 'drupal7' : $cms; + $items = [ + 'bower_components/smartmenus/dist/css/sm-core-css.css', + 'css/crm-menubar.css', + "css/menubar-$cms.css", + ]; + foreach ($items as $item) { + $e->content .= file_get_contents(self::singleton()->getPath('civicrm', $item)); + } + $vars = [ + 'resourceBase' => rtrim($config->resourceBase, '/'), + ]; + foreach ($vars as $var => $val) { + $e->content = str_replace('$' . $var, $val, $e->content); + } + } + /** * Provide a list of available entityRef filters. * diff --git a/css/crm-menubar.css b/css/crm-menubar.css index 06800779a6..25aa00ca5c 100644 --- a/css/crm-menubar.css +++ b/css/crm-menubar.css @@ -163,7 +163,7 @@ ul.crm-quickSearch-results.ui-state-disabled { } #civicrm-menu-nav .crm-logo-sm { - background: url(../i/logo_sm.png) no-repeat; + background: url($resourceBase/i/logo_sm.png) no-repeat; display: inline-block; width: 16px; height: 16px; @@ -316,7 +316,7 @@ body.crm-menubar-over-cms-menu #crm-menubar-toggle-position a i { left: 5px; width: 18px; height: 18px; - background: url(../i/logo_lg.png) no-repeat; + background: url($resourceBase/i/logo_lg.png) no-repeat; background-size: 18px; top: 6px; }