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

Prepare AdminThemeUikit for new design theme options

This commit is contained in:
Ryan Cramer
2025-04-25 14:29:52 -04:00
parent 69823256fb
commit a3dbd1b28f
4 changed files with 97 additions and 15 deletions

View File

@@ -799,8 +799,7 @@ abstract class AdminThemeFramework extends AdminTheme {
*
*/
public function renderExtraMarkup($for) {
static $extras = array();
if(empty($extras)) $extras = $this->getExtraMarkup();
$extras = $this->getExtraMarkup();
return isset($extras[$for]) ? $extras[$for] : '';
}

View File

@@ -22,6 +22,8 @@
* @property int $toggleBehavior (0=Standard, 1=Consistent)
* @property string $configPhpHash Hash used internally to detect changes to $config->AdminThemeUikit settings.
* @property int $cssVersion Current version number of core CSS/LESS files
* @property string $themeName One of blank (original) or name of theme style
* @property array $themeInfos where theme style files are located
*
* @method string renderBreadcrumbs()
* @method string getUikitCSS()
@@ -104,6 +106,8 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
$this->set('ukGrid', false);
$this->set('configPhpHash', '');
$this->set('cssVersion', 0);
// $this->set('themeName', ''); // @todo
$this->set('themeInfos', array('z' => 'z')); // z=sleeping
$this->setClasses(array(
'input' => 'uk-input',
'input-small' => 'uk-input uk-form-small',
@@ -1006,10 +1010,8 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
*/
public function getLogo(array $options = array()) {
/** @var Config $config */
$config = $this->wire('config');
/** @var Sanitizer $sanitizer */
$sanitizer = $this->wire('sanitizer');
$config = $this->wire()->config;
$sanitizer = $this->wire()->sanitizer;
$defaults = array(
'getURL' => false,
@@ -1022,8 +1024,16 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
$logoURL = $this->get('logoURL');
$logoQS = '';
$svg = false;
if(empty($logoURL) || $options['getNative'] || strpos($logoURL, '//') !== false) {
$svgName = 'logo.svg';
$themeName = $this->themeName;
$themeInfo = $themeName ? $this->getThemeInfo() : [];
$themeLogo = empty($themeInfo) ? '' : $themeInfo['path'] . $svgName;
if($themeLogo && (empty($logoURL) || $options['getNative']) && file_exists($themeLogo)) {
if($options['getURL']) return $themeInfo['url'] . $svgName;
return file_get_contents($themeLogo);
} else if(empty($logoURL) || $options['getNative'] || strpos($logoURL, '//') !== false) {
$native = true;
$logoURL = $this->url() . self::logo;
} else {
@@ -1053,12 +1063,7 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
if($logoQS) $logoURL .= '?' . $sanitizer->entities($logoQS);
if($native && false) { // @todo
$logoURL = $config->urls($this) . 'pw.svg';
$img = file_get_contents(__DIR__ . '/pw.svg');
} else {
$img = "<img src='$logoURL' $attr/>";
}
$img = "<img src='$logoURL' $attr/>";
return $options['getURL'] ? $logoURL : $img;
}
@@ -1162,6 +1167,47 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
return parent::getHeadJS();
}
/**
* Get info for theme style
*
* @param string $themeName Optionally specify name of theme style, or omit to use current
* @return array
* @throws WireException
*
*/
public function getThemeInfo($themeName = '') {
if(empty($themeName)) $themeName = $this->themeName;
$themeInfos = $this->themeInfos;
if(isset($themeInfos['z'])) {
// wakeup
$config = $this->wire()->config;
$thisPath = $config->paths($this);
$themesPath = $thisPath . 'themes/';
$rootLen = strlen($config->paths->root);
if(is_dir($themesPath)) {
foreach(new \DirectoryIterator($themesPath) as $file) {
if(!$file->isDir() || $file->isDot()) continue;
$basename = $file->getBasename();
if(strpos($basename, '.') === 0) continue;
$themePath = $thisPath . "themes/$basename/";
$themeUrl = $config->urls->root . substr($themePath, $rootLen);
$themeInfos[$basename] = [
'name' => $basename,
'path' => $themePath,
'url' => $themeUrl
];
}
}
unset($themeInfos['z']);
$this->themeInfos = $themeInfos;
}
return $themeName && isset($themeInfos[$themeName]) ? $themeInfos[$themeName] : [];
}
/**
* Module configuration
*

View File

@@ -21,6 +21,12 @@ if(!defined("PROCESSWIRE")) die();
/** @var Paths $urls */
/** @var string $layout */
/** @var Process $process */
$themeInfo = $adminTheme->getThemeInfo();
if(!empty($themeInfo)) {
$themePhpFile = "$themeInfo[path]$themeInfo[name].php";
if(file_exists($themePhpFile)) include($themePhpFile);
}
$adminTheme->renderExtraMarkup('x'); // forces it to cache
if(!isset($content)) $content = '';
@@ -76,4 +82,3 @@ if(!isset($content)) $content = '';
</body>
</html><?php

View File

@@ -45,6 +45,38 @@ class AdminThemeUikitConfigHelper extends Wire {
$layout = $adminTheme->layout;
$userTemplateURL = $this->wire('config')->urls->admin . 'setup/template/edit?id=3';
$adminTheme->getThemeInfo(); // init
$themeInfos = $adminTheme->themeInfos;
if(count($themeInfos)) {
$configFiles = [];
$f = $inputfields->InputfieldRadios;
$f->attr('id+name', 'themeName');
$f->label = $this->_('Theme style');
$f->icon = 'photo';
// $default = '[span.detail] ' . __('(default)') . ' [/span]';
foreach($themeInfos as $name => $info) {
$f->addOption($name, ucfirst($name));
$configFile = $info['path'] . 'config.php';
if(is_file($configFile)) $configFiles[$name] = $configFile;
}
$f->addOption('', $this->_('Original'));
$value = $adminTheme->themeName;
$f->val($value);
$f->themeOffset = 1;
$inputfields->add($f);
foreach($configFiles as $name => $configFile) {
$fs = $inputfields->InputfieldFieldset;
$inputfields->add($fs);
$fs->themeOffset = 1;
$fs->attr('name', "_theme_$name");
$fs->label = $this->_('Theme style settings:') . ' ' . $name;
$fs->showIf = "themeName=$name";
$this->wire()->files->render($configFile, [ 'inputfields' => $fs ]);
}
}
/** @var InputfieldFieldset $fieldset */
$fieldset = $modules->get('InputfieldFieldset');
$fieldset->label = $this->_('Masthead + navigation');