refactor: enhance ThemeHelper class to support unlimited width and update DefaultPageLayout.php for new constructor parameters

This commit is contained in:
Zack Spear
2025-04-04 19:32:11 -07:00
parent 83363f1cdd
commit 6d219e4778
3 changed files with 51 additions and 13 deletions

View File

@@ -12,7 +12,7 @@
?>
<?
require_once "$docroot/plugins/dynamix/include/ThemeHelper.php";
$themeHelper = new ThemeHelper($display['theme']);
$themeHelper = new ThemeHelper($display['theme'], $display['width']);
$theme = $themeHelper->getThemeName(); // keep $theme, $themes1, $themes2 vars for plugin backwards compatibility for the time being
$themes1 = $themeHelper->isTopNavTheme();
$themes2 = $themeHelper->isSidebarTheme();

View File

@@ -31,19 +31,44 @@ class ThemeHelper {
private bool $sidebarTheme;
private bool $darkTheme;
private bool $lightTheme;
private string $themeHtmlClass;
private string $fgcolor;
private bool $unlimitedWidth = false;
/**
* Constructor for ThemeHelper
*
* @param string|null $theme The theme name (optional)
* @param '1'|null $width The width of the theme (optional)
*/
public function __construct(?string $theme = null) {
if ($theme === null) {
throw new \RuntimeException(self::INIT_ERROR);
public function __construct(?string $theme = null, ?string $width = null) {
if ($theme !== null) {
$this->initWithCurrentThemeSetting($theme);
}
$this->initWithCurrentThemeSetting($theme);
if ($width !== null) {
$this->setWidth($width);
}
throw new \RuntimeException(self::INIT_ERROR);
}
/**
* Set the width setting
*
* @param string $width The width setting ('1' for unlimited, empty string for boxed)
* @return void
*/
public function setWidth(string $width): void {
$this->unlimitedWidth = ($width === '1');
}
/**
* Check if unlimited width is enabled
*
* @return bool
*/
public function isUnlimitedWidth(): bool {
return $this->unlimitedWidth;
}
/**
@@ -60,11 +85,6 @@ class ThemeHelper {
$this->darkTheme = in_array($this->themeName, self::DARK_THEMES);
$this->lightTheme = in_array($this->themeName, self::LIGHT_THEMES);
$this->themeHtmlClass = "Theme--{$this->themeName}";
if ($this->sidebarTheme) {
$this->themeHtmlClass .= " Theme--sidebar";
}
$this->fgcolor = self::FGCOLORS[$this->themeName] ?? self::COLOR_BLACK;
}
@@ -88,8 +108,26 @@ class ThemeHelper {
return $this->lightTheme;
}
/**
* Get the theme HTML class string
*
* @return string
*/
public function getThemeHtmlClass(): string {
return $this->themeHtmlClass;
$classes = ["Theme--{$this->themeName}"];
if ($this->sidebarTheme) {
$classes[] = "Theme--sidebar";
}
if ($this->topNavTheme) {
$classes[] = "Theme--nav-top";
}
$classes[] = $this->unlimitedWidth ? "Theme--unlimited-width" : "Theme--boxed-width";
return implode(' ', $classes);
}
public function getFgColor(): string {

View File

@@ -114,7 +114,7 @@ Files like `UserList.css`, `ShareList.css` that provide reusable styles:
### Theme Classes
- Main theme: `.Theme--{themename}`
- Layout variants: `.Theme--sidebar`, `.Theme--topnav`
- Layout variants: `.Theme--sidebar`, `.Theme--nav-top`
## Best Practices