From 3bed484c8078412c83ebe5bbf1c54fe144c28fae Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Tue, 9 Apr 2019 06:08:10 -0400 Subject: [PATCH] Fix issue processwire/processwire-issues#845 --- .../AdminThemeUikit/AdminThemeUikit.module | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module b/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module index d525647c..588013e6 100644 --- a/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module +++ b/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module @@ -120,7 +120,9 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl // disable sidebar layout if SystemNotifications is active if($sidenav && $modules->isInstalled('SystemNotifications')) { - if(!$modules->get('SystemNotifications')->disabled) { + /** @var SystemNotifications $systemNotifications */ + $systemNotifications = $modules->get('SystemNotifications'); + if(!$systemNotifications->disabled) { $this->layout = ''; $sidenav = false; } @@ -726,22 +728,38 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl * Render sidebar navigation that uses uk-nav * * The contents is the same as the Primary nav, except that output is prepared for sidebar. + * This method uses a session-cached version. To clear the cache, logout then log back in. * * @return string * */ public function renderSidebarNavItems() { - $cache = self::dev ? '' : $this->wire('session')->getFor($this, 'sidenav'); - - if($cache) { - $this->markCurrentNavItems($cache); - return $cache; + // see if we can get it from the cache + $out = self::dev ? '' : $this->wire('session')->getFor($this, 'sidenav'); + + if(empty($out)) { + $out = $this->renderSidebarNavCache(); + $this->wire('session')->setFor($this, 'sidenav', $out); } + + $out = str_replace('', $this->renderUserNavLabel(), $out); + $this->markCurrentNavItems($out); + return $out; + } + + /** + * Re-renders the sidebar nav to be cached + * + * @return string + * + */ + protected function renderSidebarNavCache() { + $out = ''; $items = $this->getPrimaryNavArray(); - $ukNav = "class='uk-nav-sub uk-nav-default uk-nav-parent-icon' data-uk-nav='animation: false; multiple: true;'"; + $ulAttrs = "class='uk-nav-sub uk-nav-default uk-nav-parent-icon' data-uk-nav='animation: false; multiple: true;'"; foreach($items as $item) { @@ -758,14 +776,14 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl $childNavList = $this->renderPrimaryNavItemChildren($child['children']); $childIcon = $this->renderNavIcon('arrow-circle-right'); $childNav = - "