refactor(theme): drop dark-green and collapse theme registry to light/dark
Remove the extensible theme catalog (config/themes.php + ThemeConfigGateway) in favor of a two-entry const on SettingsAppGateway. appThemes() now returns the list directly — no container lookup, no file include. Drop the dark-green theme assets, narrow [data-theme^="dark"] selectors to [data-theme="dark"], and tighten isDarkTheme() to an exact match. Ship an idempotent migration that corrects any leftover 'dark-green' rows on users and tenants to safe defaults (light / NULL). Tenant scoping (default_theme, allow_user_theme) and per-user override stay intact; only the catalog extensibility and the third theme are removed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,6 @@ return [
|
||||
'base' => [
|
||||
'css/app-layers.css',
|
||||
'css/base/variables.base.css',
|
||||
'css/base/variables.theme-dark-green.css',
|
||||
'css/base/variables.contrast.css',
|
||||
],
|
||||
'shared' => [
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'light' => 'Light',
|
||||
'dark' => 'Dark',
|
||||
'dark-green' => 'Dark green',
|
||||
];
|
||||
@@ -26,7 +26,6 @@ use MintyPHP\Service\Settings\SettingsSessionGateway;
|
||||
use MintyPHP\Service\Settings\SettingsSmtpGateway;
|
||||
use MintyPHP\Service\Settings\SettingsSystemAuditGateway;
|
||||
use MintyPHP\Service\Settings\SettingsUserLifecycleGateway;
|
||||
use MintyPHP\Service\Settings\ThemeConfigGateway;
|
||||
use MintyPHP\Service\Tenant\TenantService;
|
||||
|
||||
final class SettingsRegistrar implements ContainerRegistrar
|
||||
@@ -65,7 +64,6 @@ final class SettingsRegistrar implements ContainerRegistrar
|
||||
$c->get(ApiTokenRepository::class),
|
||||
$c->get(AuditRecorderInterface::class)
|
||||
));
|
||||
$container->set(ThemeConfigGateway::class, static fn (AppContainer $c): ThemeConfigGateway => $c->get(SettingServicesFactory::class)->createThemeConfigGateway());
|
||||
// Branding services are registered here because they depend on settings gateways
|
||||
// and are consumed alongside settings (e.g. in UserAccessPdfService and the admin UI).
|
||||
$container->set(BrandingLogoService::class, static fn (AppContainer $c): BrandingLogoService => $c->get(BrandingServicesFactory::class)->createBrandingLogoService());
|
||||
|
||||
@@ -9,7 +9,6 @@ use MintyPHP\Repository\Tenant\TenantRepositoryInterface;
|
||||
|
||||
class SettingServicesFactory
|
||||
{
|
||||
private ?ThemeConfigGateway $themeConfigService = null;
|
||||
private ?SettingCacheService $settingCacheService = null;
|
||||
private ?SettingsCryptoGatewayInterface $settingsCryptoGateway = null;
|
||||
private ?SettingsMetadataGateway $settingsMetadataGateway = null;
|
||||
@@ -53,7 +52,6 @@ class SettingServicesFactory
|
||||
{
|
||||
return $this->settingsAppGateway ??= new SettingsAppGateway(
|
||||
$this->createSettingsMetadataGateway(),
|
||||
$this->createThemeConfigGateway(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -108,11 +106,6 @@ class SettingServicesFactory
|
||||
);
|
||||
}
|
||||
|
||||
public function createThemeConfigGateway(): ThemeConfigGateway
|
||||
{
|
||||
return $this->themeConfigService ??= new ThemeConfigGateway();
|
||||
}
|
||||
|
||||
public function createSettingsCryptoGateway(): SettingsCryptoGatewayInterface
|
||||
{
|
||||
return $this->settingsCryptoGateway ??= new SettingsCryptoGateway();
|
||||
|
||||
@@ -13,15 +13,18 @@ use MintyPHP\I18n;
|
||||
*
|
||||
* The theme CATALOG utilities (listThemes, isAllowedTheme, normalizeTheme,
|
||||
* resolveDefaultTheme) stay because consumers across Tenant / Auth / User
|
||||
* flows need to validate a theme value and resolve a safe default. There is
|
||||
* no global setting lookup in these helpers anymore — the default is a
|
||||
* hardcoded 'light' falling back to the first available catalog entry.
|
||||
* flows need to validate a theme value and resolve a safe default. The
|
||||
* catalog is a fixed two-entry list; 'light' is the hardcoded default.
|
||||
*/
|
||||
class SettingsAppGateway
|
||||
{
|
||||
private const THEMES = [
|
||||
'light' => 'Light',
|
||||
'dark' => 'Dark',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private readonly SettingsMetadataGateway $settingsMetadataGateway,
|
||||
private readonly ThemeConfigGateway $themeConfigService
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -82,14 +85,11 @@ class SettingsAppGateway
|
||||
}
|
||||
|
||||
/**
|
||||
* Catalog of available themes — purely code-level (config/themes.php),
|
||||
* not a global setting.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function listThemes(): array
|
||||
{
|
||||
return $this->themeConfigService->all();
|
||||
return self::THEMES;
|
||||
}
|
||||
|
||||
public function isAllowedTheme(?string $theme): bool
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Service\Settings;
|
||||
|
||||
class ThemeConfigGateway
|
||||
{
|
||||
private const DEFAULT_THEMES = [
|
||||
'light' => 'Light',
|
||||
'dark' => 'Dark',
|
||||
];
|
||||
|
||||
private ?array $themes = null;
|
||||
|
||||
public function all(): array
|
||||
{
|
||||
if ($this->themes !== null) {
|
||||
return $this->themes;
|
||||
}
|
||||
|
||||
$file = dirname(__DIR__, 3) . '/config/themes.php';
|
||||
if (!is_file($file)) {
|
||||
$this->themes = self::DEFAULT_THEMES;
|
||||
return $this->themes;
|
||||
}
|
||||
|
||||
$loaded = include $file;
|
||||
if (!is_array($loaded)) {
|
||||
$this->themes = self::DEFAULT_THEMES;
|
||||
return $this->themes;
|
||||
}
|
||||
|
||||
$clean = [];
|
||||
foreach ($loaded as $key => $label) {
|
||||
$themeKey = strtolower(trim((string) $key));
|
||||
$themeLabel = trim((string) $label);
|
||||
if ($themeKey === '' || $themeLabel === '') {
|
||||
continue;
|
||||
}
|
||||
$clean[$themeKey] = $themeLabel;
|
||||
}
|
||||
|
||||
// Fall back to defaults if the file returns an empty or invalid list — system must always have themes.
|
||||
$this->themes = $clean ?: self::DEFAULT_THEMES;
|
||||
return $this->themes;
|
||||
}
|
||||
}
|
||||
@@ -7,18 +7,16 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Load configured themes with a safe fallback list.
|
||||
* Available themes. Fixed two-entry catalog — light and dark.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
function appThemes(): array
|
||||
{
|
||||
if (!class_exists('MintyPHP\\Service\\Settings\\ThemeConfigGateway')) {
|
||||
return [
|
||||
'light' => 'Light',
|
||||
'dark' => 'Dark',
|
||||
];
|
||||
}
|
||||
|
||||
return app(\MintyPHP\Service\Settings\ThemeConfigGateway::class)->all();
|
||||
return [
|
||||
'light' => 'Light',
|
||||
'dark' => 'Dark',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
7
db/updates/2026-04-24-theme-simplification.sql
Normal file
7
db/updates/2026-04-24-theme-simplification.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
-- Theme simplification: collapse catalog to light + dark.
|
||||
-- Migrates any leftover 'dark-green' values back to safe defaults.
|
||||
-- Idempotent — re-runs are a no-op because the WHERE clauses filter
|
||||
-- on the exact legacy value that the preceding run already replaced.
|
||||
|
||||
UPDATE users SET theme = 'light' WHERE theme = 'dark-green';
|
||||
UPDATE tenants SET default_theme = NULL WHERE default_theme = 'dark-green';
|
||||
@@ -255,7 +255,6 @@
|
||||
"Theme": "Theme",
|
||||
"Light": "Hell",
|
||||
"Dark": "Dunkel",
|
||||
"Dark green": "Dunkelgrün",
|
||||
"Main menu": "Hauptmenü",
|
||||
"Toggle Sidebar": "Sidebar umschalten",
|
||||
"Toggle Detail Sidebar": "Detail-Seitenleiste umschalten",
|
||||
|
||||
@@ -255,7 +255,6 @@
|
||||
"Theme": "Theme",
|
||||
"Light": "Light",
|
||||
"Dark": "Dark",
|
||||
"Dark green": "Dark green",
|
||||
"Main menu": "Main menu",
|
||||
"Toggle Sidebar": "Toggle Sidebar",
|
||||
"Toggle Detail Sidebar": "Toggle Detail Sidebar",
|
||||
|
||||
@@ -14,7 +14,6 @@ final class ConfigContractsTest extends TestCase
|
||||
'config/assets.php',
|
||||
'config/routes.php',
|
||||
'config/modules.php',
|
||||
'config/themes.php',
|
||||
'config/config.php.example',
|
||||
];
|
||||
foreach ($required as $file) {
|
||||
|
||||
@@ -5,17 +5,13 @@ namespace MintyPHP\Tests\Service\Settings;
|
||||
use MintyPHP\Repository\Settings\SettingRepositoryInterface;
|
||||
use MintyPHP\Service\Settings\SettingsAppGateway;
|
||||
use MintyPHP\Service\Settings\SettingsMetadataGateway;
|
||||
use MintyPHP\Service\Settings\ThemeConfigGateway;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SettingsAppGatewayTest extends TestCase
|
||||
{
|
||||
private function createGateway(SettingRepositoryInterface $settings): SettingsAppGateway
|
||||
{
|
||||
$themeConfig = $this->createMock(ThemeConfigGateway::class);
|
||||
$themeConfig->method('all')->willReturn(['light' => 'Light', 'dark' => 'Dark']);
|
||||
|
||||
return new SettingsAppGateway(new SettingsMetadataGateway($settings), $themeConfig);
|
||||
return new SettingsAppGateway(new SettingsMetadataGateway($settings));
|
||||
}
|
||||
|
||||
public function testGetAppTitleReturnsNullWhenEmpty(): void
|
||||
|
||||
@@ -8,7 +8,6 @@ use MintyPHP\Service\Settings\SettingsFrontendTelemetryGateway;
|
||||
use MintyPHP\Service\Settings\SettingsMetadataGateway;
|
||||
use MintyPHP\Service\Settings\SettingsSmtpGateway;
|
||||
use MintyPHP\Service\Settings\SettingsSystemAuditGateway;
|
||||
use MintyPHP\Service\Settings\ThemeConfigGateway;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class SettingsGatewayNormalizationTest extends TestCase
|
||||
@@ -124,9 +123,6 @@ final class SettingsGatewayNormalizationTest extends TestCase
|
||||
|
||||
private function newAppGateway(SettingRepositoryInterface $settingRepository): SettingsAppGateway
|
||||
{
|
||||
$themeConfig = $this->createMock(ThemeConfigGateway::class);
|
||||
$themeConfig->method('all')->willReturn(['light' => 'Light', 'dark' => 'Dark']);
|
||||
|
||||
return new SettingsAppGateway(new SettingsMetadataGateway($settingRepository), $themeConfig);
|
||||
return new SettingsAppGateway(new SettingsMetadataGateway($settingRepository));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace MintyPHP\Tests\Support;
|
||||
|
||||
use MintyPHP\App\AppContainer;
|
||||
use MintyPHP\Service\Settings\SettingCacheService;
|
||||
use MintyPHP\Service\Settings\ThemeConfigGateway;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -27,10 +26,6 @@ class ThemeResolutionTest extends TestCase
|
||||
|
||||
$this->container = new AppContainer();
|
||||
|
||||
$themeConfig = $this->createMock(ThemeConfigGateway::class);
|
||||
$themeConfig->method('all')->willReturn(['light' => 'Light', 'dark' => 'Dark']);
|
||||
$this->container->set(ThemeConfigGateway::class, fn () => $themeConfig);
|
||||
|
||||
$this->setAppSettings([]);
|
||||
|
||||
$this->pushAppContainer($this->container);
|
||||
|
||||
@@ -602,7 +602,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
[data-theme^="dark"] {
|
||||
[data-theme="dark"] {
|
||||
color-scheme: dark;
|
||||
--app-background-color: rgb(19, 22.5, 30.5);
|
||||
--app-sidebar-background-color: var(--app-background-color);
|
||||
@@ -830,7 +830,7 @@
|
||||
--app-icon-invalid: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(149.5, 74, 80)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'%3E%3C/line%3E%3C/svg%3E");
|
||||
}
|
||||
|
||||
[data-theme^="dark"]
|
||||
[data-theme="dark"]
|
||||
input:is(
|
||||
[type="submit"],
|
||||
[type="button"],
|
||||
|
||||
@@ -37,8 +37,8 @@ html[data-contrast="high"][data-theme="light"],
|
||||
--app-action-danger-outline-background: rgba(143, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
html[data-contrast="high"][data-theme^="dark"],
|
||||
[data-contrast="high"][data-theme^="dark"] {
|
||||
html[data-contrast="high"][data-theme="dark"],
|
||||
[data-contrast="high"][data-theme="dark"] {
|
||||
--app-background-color: #000;
|
||||
--app-sidebar-background-color: var(--app-background-color);
|
||||
--app-color: #f8fafc;
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
@charset "UTF-8";
|
||||
|
||||
@layer tokens {
|
||||
[data-theme="dark-green"] {
|
||||
--app-background-color: #0f1713;
|
||||
--app-sidebar-background-color: var(--app-background-color);
|
||||
--app-color: #cfe0d6;
|
||||
--app-text-selection-color: rgba(64, 170, 118, 0.25);
|
||||
--app-muted-color: #8a9b91;
|
||||
--app-muted-border-color: #223028;
|
||||
--app-form-element-background-color: #141f19;
|
||||
--app-form-element-border-color: #26362d;
|
||||
--app-form-element-color: #d5e6dc;
|
||||
--app-form-element-placeholder-color: #7f9187;
|
||||
--app-card-background-color: #141f19;
|
||||
--app-card-border-color: #223028;
|
||||
--app-card-sectioning-background-color: #1a261f;
|
||||
--app-details-card-open-summary-bg: #203026;
|
||||
--app-dropdown-background-color: #141f19;
|
||||
--app-dropdown-border-color: #223028;
|
||||
--app-dropdown-hover-background-color: #1f2a24;
|
||||
--app-modal-overlay-background-color: rgba(7, 10, 8, 0.75);
|
||||
--app-progress-background-color: #223028;
|
||||
--app-primary-h-base: 145;
|
||||
--app-primary-s-base: 38%;
|
||||
--app-primary-l-base: 38%;
|
||||
--badge-success-bg: #123225;
|
||||
--badge-success-color: #8de2b4;
|
||||
--badge-success-border: #1f4a36;
|
||||
--badge-danger-bg: #361a1d;
|
||||
--badge-danger-color: #f4a3ad;
|
||||
--badge-danger-border: #5a2b32;
|
||||
--badge-info-bg: #142735;
|
||||
--badge-info-color: #9ad2e0;
|
||||
--badge-info-border: #214156;
|
||||
--badge-warn-bg: #3a2a12;
|
||||
--badge-warn-color: #ffdf9e;
|
||||
--badge-warn-border: #5a401b;
|
||||
--badge-neutral-bg: #1b2620;
|
||||
--badge-neutral-color: #cfe0d6;
|
||||
--badge-neutral-border: #2a3a31;
|
||||
--app-tile-bg: rgb(20 28 24);
|
||||
--app-blockquote-background-color: rgb(20 28 24);
|
||||
}
|
||||
}
|
||||
@@ -691,11 +691,6 @@
|
||||
filter: invert(1);
|
||||
}
|
||||
|
||||
html[data-theme="dark-green"] button.gridjs-sort,
|
||||
html[data-theme="dark-green"] button.gridjs-sort-neutral {
|
||||
filter: invert(1);
|
||||
}
|
||||
|
||||
button.gridjs-sort {
|
||||
background-color: transparent;
|
||||
background-position-x: center;
|
||||
|
||||
@@ -8,7 +8,7 @@ const setTheme = (theme) => {
|
||||
document.documentElement.dataset.theme = theme;
|
||||
};
|
||||
|
||||
const isDarkTheme = (theme) => theme && theme.startsWith('dark');
|
||||
const isDarkTheme = (theme) => theme === 'dark';
|
||||
|
||||
const setIcon = (iconEl, theme) => {
|
||||
if (!iconEl) {
|
||||
|
||||
Reference in New Issue
Block a user