Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook to alter menubar css variables & fix breakpoint in WP #14135

Merged
merged 4 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CRM/Core/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,9 @@ public function coreResourceList($region) {
$items[] = 'js/crm.menubar.js';
$items[] = Civi::service('asset_builder')->getUrl('crm-menubar.css', [
'color' => Civi::settings()->get('menubar_color'),
'height' => 40,
'breakpoint' => 768,
'opacity' => .88,
]);
$items[] = [
'menubar' => [
Expand Down Expand Up @@ -852,9 +855,11 @@ public static function renderMenubarStylesheet(GenericHookEvent $e) {
}
$vars = [
'resourceBase' => rtrim($config->resourceBase, '/'),
'menubarHeight' => '40px',
'menubarHeight' => $e->params['height'] . 'px',
'breakMin' => $e->params['breakpoint'] . 'px',
'breakMax' => ($e->params['breakpoint'] - 1) . 'px',
'menubarColor' => $color,
'semiTransparentMenuColor' => 'rgba(' . implode(', ', CRM_Utils_Color::getRgb($color)) . ', .85)',
'menuItemColor' => 'rgba(' . implode(', ', CRM_Utils_Color::getRgb($color)) . ", {$e->params['opacity']})",
'highlightColor' => CRM_Utils_Color::getHighlight($color),
'textColor' => CRM_Utils_Color::getContrast($color, '#333', '#ddd'),
];
Expand Down
18 changes: 18 additions & 0 deletions CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,24 @@ public static function alterAngular($angular) {
Civi::dispatcher()->dispatch('hook_civicrm_alterAngular', $event);
}

/**
* This hook is called when building a link to a semi-static asset.
*
* @param string $asset
* The name of the asset.
* Ex: 'angular.json'
* @param array $params
* List of optional arguments which influence the content.
* @return null
* the return value is ignored
*/
public static function getAssetUrl(&$asset, &$params) {
return self::singleton()->invoke(['asset', 'params'],
$asset, $params, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
'civicrm_getAssetUrl'
);
}

/**
* This hook is called whenever the system builds a new copy of
* semi-static asset.
Expand Down
1 change: 1 addition & 0 deletions CRM/Utils/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
* @method static setHttpHeader(string $name, string $value) Set http header.
* @method static array synchronizeUsers() Create CRM contacts for all existing CMS users.
* @method static appendCoreResources(\Civi\Core\Event\GenericHookEvent $e) Callback for hook_civicrm_coreResourceList.
* @method static alterAssetUrl(\Civi\Core\Event\GenericHookEvent $e) Callback for hook_civicrm_getAssetUrl.
*/
class CRM_Utils_System {

Expand Down
8 changes: 8 additions & 0 deletions CRM/Utils/System/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,14 @@ public function logger($message) {
public function appendCoreResources(\Civi\Core\Event\GenericHookEvent $e) {
}

/**
* Modify dynamic assets.
*
* @param \Civi\Core\Event\GenericHookEvent $e
*/
public function alterAssetUrl(\Civi\Core\Event\GenericHookEvent $e) {
}

/**
* @param string $name
* @param string $value
Expand Down
10 changes: 10 additions & 0 deletions CRM/Utils/System/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,16 @@ public function appendCoreResources(\Civi\Core\Event\GenericHookEvent $e) {
$e->list[] = 'js/crm.wordpress.js';
}

/**
* @inheritDoc
*/
public function alterAssetUrl(\Civi\Core\Event\GenericHookEvent $e) {
// Set menubar breakpoint to match WP admin theme
if ($e->asset == 'crm-menubar.css') {
$e->params['breakpoint'] = 783;
}
}

/**
* @inheritDoc
*/
Expand Down
2 changes: 2 additions & 0 deletions Civi/Core/AssetBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public function isValidName($name) {
* Ex: 'http://example.org/files/civicrm/dyn/angular.abcd1234abcd1234.json'.
*/
public function getUrl($name, $params = []) {
\CRM_Utils_Hook::getAssetUrl($name, $params);

if (!$this->isValidName($name)) {
throw new \RuntimeException("Invalid dynamic asset name");
}
Expand Down
1 change: 1 addition & 0 deletions Civi/Core/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ public function createEventDispatcher($container) {
$dispatcher->addListener('hook_civicrm_buildAsset', ['\CRM_Utils_VisualBundle', 'buildAssetCss']);
$dispatcher->addListener('hook_civicrm_buildAsset', ['\CRM_Core_Resources', 'renderMenubarStylesheet']);
$dispatcher->addListener('hook_civicrm_coreResourceList', ['\CRM_Utils_System', 'appendCoreResources']);
$dispatcher->addListener('hook_civicrm_getAssetUrl', ['\CRM_Utils_System', 'alterAssetUrl']);
$dispatcher->addListener('civi.dao.postInsert', ['\CRM_Core_BAO_RecurringEntity', 'triggerInsert']);
$dispatcher->addListener('civi.dao.postUpdate', ['\CRM_Core_BAO_RecurringEntity', 'triggerUpdate']);
$dispatcher->addListener('civi.dao.postDelete', ['\CRM_Core_BAO_RecurringEntity', 'triggerDelete']);
Expand Down
6 changes: 3 additions & 3 deletions css/crm-menubar.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ body.crm-menubar-over-cms-menu #crm-menubar-toggle-position a i {
transform: rotate(180deg);
}

@media (min-width: 768px) {
@media (min-width: $breakMin) {

/* Switch to desktop layout
-----------------------------------------------
Expand Down Expand Up @@ -219,7 +219,7 @@ body.crm-menubar-over-cms-menu #crm-menubar-toggle-position a i {
}

#civicrm-menu li a {
background-color: $semiTransparentMenuColor;
background-color: $menuItemColor;
color: $textColor;
}

Expand Down Expand Up @@ -263,7 +263,7 @@ body.crm-menubar-over-cms-menu #crm-menubar-toggle-position a i {
}
}

@media (max-width: 768px) {
@media (max-width: $breakMax) {
/* hide the menu in mobile view */
#crm-menubar-state:not(:checked) ~ #civicrm-menu {
display: none;
Expand Down
4 changes: 2 additions & 2 deletions css/menubar-backdrop.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@media (min-width: 768px) {
@media (min-width: $breakMin) {

body.crm-menubar-visible.crm-menubar-over-cms-menu {
border-top: 0 none !important;
Expand Down Expand Up @@ -28,7 +28,7 @@
}

}
@media (max-width: 768px) {
@media (max-width: $breakMax) {

body.backdrop-admin-bar-position-absolute #civicrm-menu-nav {
position: absolute;
Expand Down
6 changes: 3 additions & 3 deletions css/menubar-drupal7.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@media (min-width: 768px) {
@media (min-width: $breakMin) {

body.crm-menubar-visible.crm-menubar-over-cms-menu #toolbar {
display: none;
Expand Down Expand Up @@ -67,7 +67,7 @@
}

/* For adminimal_admin_menu */
@media (min-width: 768px) and (max-width: 1024px) {
@media (min-width: $breakMin) and (max-width: 1024px) {

body.crm-menubar-visible.crm-menubar-over-cms-menu.admin-menu.adminimal-menu > .slicknav_menu {
display: none;
Expand All @@ -80,7 +80,7 @@
}
}

@media (max-width: 768px) {
@media (max-width: $breakMax) {

body.toolbar.crm-menubar-visible #toolbar-home {
visibility: hidden;
Expand Down
2 changes: 1 addition & 1 deletion css/menubar-drupal8.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ nav#civicrm-menu-nav .crm-menubar-toggle-btn-icon {
left: 44px;
}

@media (min-width: 768px) {
@media (min-width: $breakMin) {

body.crm-menubar-visible.crm-menubar-over-cms-menu #toolbar-administration {
display: none;
Expand Down
4 changes: 2 additions & 2 deletions css/menubar-joomla.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@media (min-width: 768px) {
@media (min-width: $breakMin) {

body.crm-menubar-over-cms-menu.crm-menubar-visible {
padding-top: $menubarHeight;
Expand All @@ -15,7 +15,7 @@
}

}
@media (max-width: 768px) {
@media (max-width: $breakMax) {

body #civicrm-menu-nav {
position: absolute;
Expand Down
6 changes: 3 additions & 3 deletions css/menubar-wordpress.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@media (min-width: 768px) {
@media (min-width: $breakMin) {

body.crm-menubar-over-cms-menu.crm-menubar-visible #wpbody {
padding-top: 8px;
Expand Down Expand Up @@ -33,7 +33,7 @@
}

}
@media (min-width: 768px) and (max-width: 960px) {
@media (min-width: $breakMin) and (max-width: 960px) {

/* For the auto-fold toolbar */
.wp-toolbar body.crm-menubar-below-cms-menu.auto-fold > #civicrm-menu-nav #civicrm-menu {
Expand All @@ -42,7 +42,7 @@
}

}
@media (max-width: 768px) {
@media (max-width: $breakMax) {

body #civicrm-menu-nav .crm-menubar-toggle-btn {
position: absolute;
Expand Down