1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-14 02:34:24 +02:00

Updates to make AdminThemeUikit easier to extend with an AdminThemeUikit descending module

This commit is contained in:
Ryan Cramer
2021-01-06 10:55:30 -05:00
parent ea00f4b940
commit 3370e10802
17 changed files with 136 additions and 43 deletions

View File

@@ -10,10 +10,12 @@
* This file is licensed under the MIT license.
* https://processwire.com/about/license/mit/
*
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
* https://processwire.com
*
* @property int|string $version Current admin theme version
* @property string $url URL to admin theme
* @property string $path Disk path to admin theme
*
* @method void install()
* @method void uninstall()
@@ -156,14 +158,55 @@ abstract class AdminTheme extends WireData implements Module {
if($session->get('hidpi')) $this->addBodyClass('hidpi-device');
if($session->get('touch')) $this->addBodyClass('touch-device');
$this->addBodyClass($this->className());
}
/**
* Get property
*
* @param string $key
* @return int|mixed|null|string
*
*/
public function get($key) {
if($key == 'version') return $this->version;
if($key === 'version') return $this->version;
if($key === 'url') return $this->url();
if($key === 'path') return $this->path();
return parent::get($key);
}
/**
* Get URL to this admin theme
*
* @return string
* @since 3.0.171
*
*/
public function url() {
return $this->wire()->config->urls($this->className());
}
/**
* Get disk path to this admin theme
*
* @return string
* @since 3.0.171
*
*/
public function path() {
$config = $this->wire()->config;
$path = $config->paths($this->className());
if(empty($path)) {
$class = $this->className();
$path = $config->paths->modules . "AdminTheme/$class/";
if(!is_dir($path)) {
$path = $config->paths->siteModules . "$class/";
if(!is_dir($path)) $path = __DIR__;
}
}
return $path;
}
/**
* Get predefined translated label by key for labels shared among admin themes
@@ -189,7 +232,8 @@ abstract class AdminTheme extends WireData implements Module {
*
*/
public function isCurrent() {
return $this->wire('adminTheme') === $this;
$adminTheme = $this->wire()->adminTheme;
return $adminTheme && $adminTheme->className() === $this->className();
}
/**

View File

@@ -4,7 +4,13 @@
* AdminTheme Framework
*
* The methods in this class may eventually be merged to AdminTheme.php,
* but are isolated to this class during development.
* but are isolated to this class during development.
*
* This file is licensed under the MIT license.
* https://processwire.com/about/license/mit/
*
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
* https://processwire.com
*
* @property bool $isSuperuser
* @property bool $isEditor
@@ -65,6 +71,8 @@ abstract class AdminThemeFramework extends AdminTheme {
public function wired() {
$this->sanitizer = $this->wire('sanitizer');
$user = $this->wire()->user;
$this->isLoggedIn = $user && $user->isLoggedin();
parent::wired();
}
@@ -95,13 +103,12 @@ abstract class AdminThemeFramework extends AdminTheme {
public function init() {
$user = $this->wire('user');
if(!$user->isLoggedin() && $this->useAsLogin) $this->setCurrent();
if(!$this->isLoggedIn && $this->useAsLogin) $this->setCurrent();
parent::init();
// if this is not the current admin theme, exit now so no hooks are attached
if(!$this->isCurrent()) return;
$this->isLoggedIn = $user->isLoggedin();
$this->isSuperuser = $this->isLoggedIn && $user->isSuperuser();
$this->isEditor = $this->isLoggedIn && ($this->isSuperuser || $user->hasPermission('page-edit'));
$this->includeInitFile();
@@ -119,7 +126,7 @@ abstract class AdminThemeFramework extends AdminTheme {
*/
public function includeInitFile() {
$config = $this->wire('config');
$initFile = $config->paths->adminTemplates . 'init.php';
$initFile = $this->path() . 'init.php';
if(file_exists($initFile)) {
if(strpos($initFile, $config->paths->site) === 0) {
// admin themes in /site/modules/ may be compiled

View File

@@ -163,6 +163,7 @@
* @property string|null $pagerHeadTags Populated at runtime to contain `<link rel=prev|next />` tags for document head, after pagination has been rendered by MarkupPagerNav module. #pw-group-runtime
* @property array $statusFiles File inclusions for ProcessWires runtime statuses/states. #pw-group-system @since 3.0.142
* @property int $status Value of current system status/state corresponding to ProcessWire::status* constants. #pw-internal
* @property null|bool $disableUnknownMethodException Disable the “Method does not exist or is not callable in this context” exception. (default=null) #pw-internal
*
* @property int $rootPageID Page ID of homepage (usually 1) #pw-group-system-IDs
* @property int $adminRootPageID Page ID of admin root page #pw-group-system-IDs

View File

@@ -6,7 +6,7 @@
* This file is designed for inclusion by /site/templates/admin.php template and all the variables
* it references are from your template namespace.
*
* Copyright 2018 by Ryan Cramer
* Copyright 2021 by Ryan Cramer
*
* @var Config $config
* @var User $user
@@ -18,6 +18,7 @@
* @var Sanitizer $sanitizer
* @var Session $session
* @var Notices $notices
* @var AdminTheme $adminTheme
*
*
*/
@@ -99,6 +100,12 @@ function _checkForMaxInputVars(WireInput $input) {
}
}
// fallback theme if one not already present
if(empty($adminTheme)) {
$adminTheme = $modules->get($config->defaultAdminTheme ? $config->defaultAdminTheme : 'AdminThemeUikit');
if(empty($adminTheme)) $adminTheme = $modules->get('AdminThemeUikit');
if($adminTheme) $wire->wire('adminTheme', $adminTheme);
}
// notify superuser if there is an http host error
if($user->isSuperuser()) _checkForHttpHostError($config);
@@ -214,7 +221,11 @@ if($controller && $controller->isAjax()) {
echo $content;
} else {
if(!strlen($content)) $content = '<p>' . __('The process returned no content.') . '</p>';
$adminThemeFile = $config->paths->adminTemplates . 'default.php';
if($adminTheme) {
$adminThemeFile = $adminTheme->path() . 'default.php';
} else {
$adminThemeFile = $config->paths->adminTemplates . 'default.php';
}
if(strpos($adminThemeFile, $config->paths->site) === 0) {
// @todo determine if compilation needed
$adminThemeFile = $wire->files->compile($adminThemeFile);