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
.
*
* @return string
*/
- public function renderBreadcrumbs(HookEvent $event)
+ protected function renderBreadcrumbs(HookEvent $event)
{
if (!$event->return) {
return;
}
$process = $this->wire('page')->process;
- if ($process == 'ProcessPageList') {
+ if ('ProcessPageList' == $process) {
return '';
}
$breadcrumbs = $this->wire('breadcrumbs');
- $out = '';
+ $out = '';
// don't show breadcrumbs if only one of them (subjective)
- if (count($breadcrumbs) < 2 && $process != 'ProcessPageEdit') {
+ if (count($breadcrumbs) < 2 && 'ProcessPageEdit' != $process) {
return '';
}
- if (strpos($this->layout, 'sidenav') === false) {
- $out = '- '.$event->object->renderQuickTreeLink().'
';
+ if (false === strpos($this->layout, 'sidenav')) {
+ $out = '- ' . $event->object->renderQuickTreeLink() . '
';
}
foreach ($breadcrumbs as $breadcrumb) {
@@ -128,95 +158,43 @@ public function renderBreadcrumbs(HookEvent $event)
$pageid = explode('open=', $breadcrumb->url);
$pageid = end($pageid);
if (wire('pages')->get($pageid)->editable()) {
- $edit = " $icon";
+ $edit = " {$icon}";
}
- } elseif (strpos($breadcrumb->url, '../') !== false && wire('process')) {
+ } elseif (false !== strpos($breadcrumb->url, '../') && wire('process')) {
// make sure we're editing a page and not a user
if (method_exists(wire('process'), 'getPage')) {
$pageid = wire('process')->getPage()->parent->id;
if (wire('pages')->get($pageid)->editable()) {
- $edit = " $icon";
+ $edit = " {$icon}";
}
// modify open
- $breadcrumb->url = "../?open=$pageid";
+ $breadcrumb->url = "../?open={$pageid}";
}
}
- $out .= "- $title$edit
";
+ $out .= "- {$title}{$edit}
";
}
if ($out) {
- $out = "";
+ $out = "";
}
$event->return = $out;
}
- /**
- * Get the primary Uikit CSS file to use.
- *
- * @return string
- *
- * @param mixed $event
- */
- private function setSettings()
- {
- //$this->message('Set css settings: '.$this->getVariant());
- $this->modules->saveConfig('AdminThemeUikit', 'cssURL', $this->getVariant());
-
- if ($this->get('uselogo')) {
- //$this->message('Set logo settings');
- $url = '/site/modules/AdminThemeBoss/';
-
- $this->modules->saveConfig('AdminThemeUikit', 'logoURL', $url.self::logo);
- } else {
- $conf['logoURL'] = $this->resetLogo();
- }
- }
-
- /**
- * Get the primary Uikit CSS file to use.
- *
- * @return string
- *
- * @param mixed $event
- */
- private function resetSettings()
- {
- //$this->message('Restored old settings');
-
- $this->modules->saveConfig('AdminThemeUikit', 'cssURL', $this->cache->getFor($this, 'cssBackup'));
- $this->resetLogo();
- }
-
- /**
- * Get the primary Uikit CSS file to use.
- *
- * @return string
- *
- * @param mixed $event
- */
- private function resetLogo()
- {
- //$this->message('restored logo settings');
- $this->modules->saveConfig('AdminThemeUikit', 'logoURL', $this->cache->getFor($this, 'logoBackup'));
- }
-
private function getVariant()
{
- $moduleInfo = $this->wire('modules')->getModuleInfo($this);
-
$variant = $this->get('variant');
- $version = $moduleInfo['version'];
- $url = '/site/modules/AdminThemeBoss/';
+ $version = $this->config->debug ? time() : $this->modules->getModuleInfoProperty($this, 'version');
+ $url = $this->config->urls->AdminThemeBoss;
// default
- $file = $url.'uikit/dist/css/uikit.pw.min.css?'.$version;
+ $file = $url . 'uikit/dist/css/uikit.pw.min.css?' . $version;
- $exists = is_file($this->config->paths->AdminThemeBoss.'uikit/dist/css/uikit.'.$variant.'.min.css');
+ $exists = is_file($this->config->paths->AdminThemeBoss . 'uikit/dist/css/uikit.' . $variant . '.min.css');
if ($exists) {
- $file = $url.'uikit/dist/css/uikit.'.$variant.'.min.css?'.$version;
+ $file = $url . 'uikit/dist/css/uikit.' . $variant . '.min.css?' . $version;
}
return $file;
diff --git a/AdminThemeBossConfig.php b/AdminThemeBossConfig.php
index ba8983c..a0aeaaa 100644
--- a/AdminThemeBossConfig.php
+++ b/AdminThemeBossConfig.php
@@ -29,65 +29,71 @@ public function __construct()
$this->add([
[
- 'type' => 'fieldset',
- 'name' => 'theme-options',
- 'label' => $this->_('Theme Options'),
- 'icon' => 'paint-brush',
- //'showIf' => 'enablemodule=1',
+ 'name' => 'enablemodule',
+ 'type' => 'checkbox',
+ 'icon' => 'check',
+ 'label' => $this->_('Enable Theme'),
+ 'checkboxLabel' => $this->_('Yes'),
+ 'description' => $this->_('You can disable this theme using this setting without uninstalling it.'),
+ 'value' => $this->get('enablemodule'),
+ ],
+ [
+ 'type' => 'fieldset',
+ 'name' => 'theme-options',
+ 'label' => $this->_('Theme Options'),
+ 'icon' => 'paint-brush',
+ 'showIf' => 'enablemodule=1',
'children' => [
[
- 'name' => 'variant',
- 'type' => 'radios',
- 'icon' => 'adjust',
- 'label' => $this->_('Color'),
- //'description' => $this->_('If "No" is selected, then upgrades will only be checked manually when you click to Setup > Upgrades.'),
- //'notes' => $this->_('Automatic upgrade check requires ProcessWire 2.5.20 or newer.'),
- //'optionColumns' => 1,
- 'value' => $this->get('variant'),
+ 'name' => 'variant',
+ 'type' => 'radios',
+ 'icon' => 'adjust',
+ 'label' => $this->_('Color'),
+ 'value' => $this->get('variant'),
'options' => [
- 'pw' => $this->_('ProcessWire Blue'),
+ 'pw' => $this->_('ProcessWire Blue'),
'vibrant' => $this->_('Vibrant Blue'),
- 'black' => $this->_('Dark Black'),
- 'pink' => $this->_('Happy Pink'),
+ 'black' => $this->_('Dark Black'),
+ 'pink' => $this->_('Happy Pink'),
],
],
],
],
[
- 'type' => 'fieldset',
- 'name' => 'advanced-options',
- 'label' => $this->_('Advanced Options'),
- 'icon' => 'cog',
+ 'type' => 'fieldset',
+ 'name' => 'advanced-options',
+ 'label' => $this->_('Advanced Options'),
+ 'icon' => 'cog',
'collapsed' => Inputfield::collapsedYes,
- //'showIf' => 'enablemodule=1',
- 'children' => [
+ 'showIf' => 'enablemodule=1',
+ 'children' => [
[
- 'name' => 'extendedbreadcrumb',
- 'type' => 'checkbox',
- 'icon' => 'link',
- 'label' => $this->_('Extended Breadcrumb'),
+ 'name' => 'extendedbreadcrumb',
+ 'type' => 'checkbox',
+ 'icon' => 'link',
+ 'label' => $this->_('Extended Breadcrumb'),
'checkboxLabel' => $this->_('Yes, use extended breadcrumb'),
- 'description' => $this->_('If set, the default breadcrumb will be extended with edit links'),
- 'notes' => $this->_('Only applies if Module BreadcrumbDropdowns is not installed.'),
- 'value' => $this->get('extendedbreadcrumb'),
+ 'description' => $this->_('If set, the default breadcrumb will be extended with edit links'),
+ 'notes' => $this->_('Only applies if Module BreadcrumbDropdowns is not installed.'),
+ 'value' => $this->get('extendedbreadcrumb'),
],
[
- 'name' => 'allusers',
- 'type' => 'checkbox',
- 'icon' => 'user',
- 'label' => $this->_('Enable For All Users'),
+ 'name' => 'allusers',
+ 'type' => 'checkbox',
+ 'icon' => 'user',
+ 'label' => $this->_('Enable For All Users'),
'checkboxLabel' => $this->_('Yes'),
- 'description' => $this->_('If enabled, [AdminThemeUikit]('.$adminThemeUrl.') will be set as theme for all users.'),
- 'value' => $this->get('allusers'),
+ 'description' => $this->_('If enabled, [AdminThemeUikit](' . $adminThemeUrl . ') will be set as theme for all users.'),
+ 'value' => $this->get('allusers'),
],
[
- 'name' => 'uselogo',
- 'type' => 'checkbox',
- 'icon' => 'bookmark',
- 'label' => $this->_('Use Dark ProcessWire Logo'),
+ 'name' => 'usedarklogo',
+ 'type' => 'checkbox',
+ 'icon' => 'bookmark',
+ 'label' => $this->_('Use Dark ProcessWire Logo'),
'checkboxLabel' => $this->_('Yes'),
- 'description' => $this->_('Set a dark theme logo for the [AdminThemeUikit]('.$adminThemeUrl.') logo settings.'),
- 'value' => $this->get('useuikitlogo'),
+ 'description' => $this->_('Set a dark theme logo for the [AdminThemeUikit](' . $adminThemeUrl . ') logo settings.'),
+ 'value' => $this->get('useuikitlogo'),
],
],
],
@@ -97,11 +103,11 @@ public function __construct()
public function getDefaults()
{
return [
- 'enablemodule' => true,
- 'variant' => 'pw',
- 'extendedbreadcrumb' => true,
- 'allusers' => true,
- 'uselogo' => true,
+ 'enablemodule' => true,
+ 'variant' => 'pw',
+ 'extendedbreadcrumb' => true,
+ 'allusers' => true,
+ 'usedarklogo' => false,
];
}
}
diff --git a/upgrade-theme.sh b/upgrade-theme.sh
old mode 100644
new mode 100755
index 769851a..5457819
--- a/upgrade-theme.sh
+++ b/upgrade-theme.sh
@@ -49,10 +49,12 @@ printf "\n\ndone…"
printf "
You can now run
-$ uikit/yarn compile-less
+$ cd uikit
+$ yarn compile-less
or for development:
-$ uikit/yarn watch
+$ cd uikit
+$ yarn watch
Enjoy…