From bbd22454501df1c565c46ea73285b290902616f0 Mon Sep 17 00:00:00 2001 From: Noel Bossart Date: Tue, 10 Sep 2019 17:34:18 +0200 Subject: [PATCH] =?UTF-8?q?Modified=20how=20the=20theme=20works=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AdminThemeBoss.info.json | 7 +- AdminThemeBoss.module.php | 188 +++++++++++++++++--------------------- AdminThemeBossConfig.php | 98 ++++++++++---------- upgrade-theme.sh | 6 +- 4 files changed, 143 insertions(+), 156 deletions(-) mode change 100644 => 100755 upgrade-theme.sh diff --git a/AdminThemeBoss.info.json b/AdminThemeBoss.info.json index 56f4f74..38ae961 100644 --- a/AdminThemeBoss.info.json +++ b/AdminThemeBoss.info.json @@ -2,9 +2,10 @@ "title": "Admin Theme Boss", "summary": "A light and clear theme based on Uikit 3, extending AdminThemeUikit", "href": "https://github.com/noelboss/AdminThemeBoss", - "version": "0.5.5", + "version": "0.5.6", "author": "Noël Bossart", "autoload": "template=admin", "icon": "diamond", - "requires": "ProcessWire>=3.0.98,AdminThemeUikit" -} + "requires": "ProcessWire>=3.0.98,AdminThemeUikit", + "installs": ["AdminThemeUikit"] +} \ No newline at end of file diff --git a/AdminThemeBoss.module.php b/AdminThemeBoss.module.php index 3128d93..fc9cd17 100644 --- a/AdminThemeBoss.module.php +++ b/AdminThemeBoss.module.php @@ -16,40 +16,22 @@ */ class AdminThemeBoss extends WireData implements Module, ConfigurableModule { - /** - * Development mode, to be used when developing this module’s code. - */ - const dev = false; - /** * Default logo image file (relative to this dir). */ const logo = 'uikit/custom/images/pw-mark.png'; - private $adminThemeUikit; - public function ___upgrade() { - //$this->message('unstall'); - $this->setSettings(); - } - - public function ___install() - { - //$this->message('unstall'); - $this->cache->saveFor($this, 'cssBackup', $this->modules->getConfig('AdminThemeUikit', 'cssURL')); - $this->cache->saveFor($this, 'logoBackup', $this->modules->getConfig('AdminThemeUikit', 'logoURL')); - $this->setSettings(); + $this->cache->deleteFor($this); } public function ___uninstall() { - //$this->message('uninstalled!'); - $this->resetSettings(); $this->cache->deleteFor($this); } - /******************************************************************************************* + /* * MARKUP RENDERING METHODS * */ @@ -59,8 +41,13 @@ public function ___uninstall() */ public function init() { - $this->adminThemeUikit = $this->modules->AdminThemeUikit; - if ($this->get('allusers') && $this->user->admin_theme !== 'AdminThemeUikit') { + $this->addHookBefore('Modules::saveConfig', $this, 'updateSettings'); + + if (!$this->get('enablemodule')) { + return; + } + + if ($this->get('allusers') && 'AdminThemeUikit' !== $this->user->admin_theme) { $this->user->setAndSave('admin_theme', 'AdminThemeUikit'); } @@ -68,20 +55,6 @@ public function init() $this->addHookAfter('AdminThemeUikit::renderBreadcrumbs', $this, 'renderBreadcrumbs'); } - $this->addHookAfter('Modules::saveConfig', function (HookEvent $event) { - $class = $event->arguments(0); - //bd($event->arguments(1)); - - if ($class == 'AdminThemeBoss') { - foreach ($event->arguments(1) as $key => $value) { - $this->set($key, $value); - } - $this->setSettings(); - } - - return $event; - }); - // add placeholder text $this->wire()->addHookAfter('ProcessLogin::buildLoginForm', function (HookEvent $event) { $event->return->get('login_name')->set('placeholder', $event->return->get('login_name')->get('label')); @@ -89,31 +62,88 @@ public function init() }); } + public function ready() + { + if (!$this->get('enablemodule')) { + return; + } + + // remove uikit css… + $this->config->styles->remove($this->modules->getConfig('AdminThemeUikit', 'cssURL')); + + // add this css… + $this->config->styles->append($this->getVariant()); + } + + protected function updateSettings(HookEvent $event) + { + $class = $event->arguments(0); + + // update logo… + if ($class == $this->className()) { + $newSettings = $event->arguments(1); + $oldSettings = $this->modules->getConfig($this); + + // save old settings… + if ($oldSettings['enablemodule'] && false == $newSettings['enablemodule']) { + $this->message('Module disabled. Settings cached…'); + $this->cache->saveFor($this, 'oldSettings', $oldSettings); + } + // reapply old settings… + elseif ($newSettings['enablemodule'] && false == $oldSettings['enablemodule']) { + // use old settings as new ones… + $newSettings = $this->cache->getFor($this, 'oldSettings'); + if ($newSettings) { + $event->arguments(1, $newSettings); + $this->cache->deleteFor($this, 'oldSettings'); + $this->message('Module settings restored…'); + } + } + + $logo = $this->urls->AdminThemeBoss . self::logo; + $uikitlogo = $this->modules->getConfig('AdminThemeUikit', 'logoURL'); + + $usedark = $newSettings['usedarklogo']; + + if (!is_file($this->config->paths->root . $uikitlogo) || $usedark && is_file($this->config->paths->root . $logo)) { + if (is_file($this->config->paths->root . $uikitlogo) && $logo !== $uikitlogo) { + $this->warning('AdminThemeUikit uses a custom logo – this setting has no effect'); + } else { + $this->modules->saveConfig('AdminThemeUikit', 'logoURL', $logo); + } + } + + if (!$usedark && $logo == $uikitlogo) { + $this->modules->saveConfig('AdminThemeUikit', 'logoURL', ''); + } + } + } + /** * Render a list of breadcrumbs (list items), excluding the containing