Skip to content

Commit 954decf

Browse files
committed
add configurable color scheme to the admin interface
- Define a structured `colors` configuration in the DI extension with required fields for branding and UI elements. - Update the `FancyAdmin` model and `BasePresenterTrait` to provide these settings directly to the template. - Refactor the layout to use the new `$colors` variable for CSS custom property generation, replacing the previous parameters-based approach.
1 parent 6f23aae commit 954decf

4 files changed

Lines changed: 37 additions & 14 deletions

File tree

src/DI/FancyAdminExtension.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ public function getConfigSchema(): Schema
5454
'context' => Expect::string()->default(null),
5555
'jsComponentsConfig' => Expect::array()->default([]),
5656
'locksDir' => Expect::string()->required(),
57+
'colors' => Expect::structure([
58+
'backgroundColor' => Expect::string()->required(),
59+
'dashboardAccentColor' => Expect::string()->required(),
60+
'primaryColor' => Expect::string()->required(),
61+
'primaryColorDark' => Expect::string()->required(),
62+
'primaryColorDark20' => Expect::string()->required(),
63+
'secondaryColor' => Expect::string()->required(),
64+
'secondaryColorDark' => Expect::string()->required(),
65+
'secondaryColorDarker' => Expect::string()->required(),
66+
'ternaryColor' => Expect::string()->required(),
67+
'ternaryTextColor' => Expect::string()->required(),
68+
'loginBackground' => Expect::string()->required(),
69+
'loginBackgroundInput' => Expect::string()->required(),
70+
'loginBackgroundInputFocus' => Expect::string()->required(),
71+
]),
5772
]);
5873
}
5974

@@ -91,6 +106,7 @@ public function loadConfiguration(): void
91106
'fullDataAclResource' => $this->config->fullDataAclResource,
92107
'jsComponentsConfig' => $this->config->jsComponentsConfig,
93108
'context' => $this->config->context,
109+
'colors' => (array) $this->config->colors,
94110
]);
95111

96112
//$this->validateTraitInterfaceCompliance();

src/Model/FancyAdmin.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct(
2626
protected Resource $fullDataAclResource,
2727
protected ?string $context,
2828
protected array $jsComponentsConfig = [],
29+
protected array $colors = [],
2930
) {}
3031

3132
public function getProject(): string
@@ -146,4 +147,9 @@ public function setFaviconFileNameSvg(string $faviconFileNameSvg): static
146147
$this->faviconFileNameSvg = $faviconFileNameSvg;
147148
return $this;
148149
}
150+
151+
public function getColors(): array
152+
{
153+
return $this->colors;
154+
}
149155
}

src/UI/Presenters/@layout.latte

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
<style>
66
{$account->getCss()|noescape}
77
</style>
8-
{elseif isset($parameters)}
8+
{else}
99
<style>
1010
body {
11-
--backgroundColor: {$parameters['colors']['backgroundColor']|noescape};
12-
--dashboardAccentColor: {$parameters['colors']['dashboardAccentColor']|noescape};
13-
--primaryColor: {$parameters['colors']['primaryColor']|noescape};
14-
--primaryColorDark: {$parameters['colors']['primaryColorDark']|noescape};
15-
--primaryColorDark20: {$parameters['colors']['primaryColorDark20']|noescape};
16-
--secondaryColor: {$parameters['colors']['secondaryColor']|noescape};
17-
--secondaryColorDark: {$parameters['colors']['secondaryColorDark']|noescape};
18-
--secondaryColorDarker: {$parameters['colors']['secondaryColorDarker']|noescape};
19-
--tertiaryColor: {$parameters['colors']['ternaryColor']|noescape};
20-
--tertiaryTextColor: {$parameters['colors']['ternaryTextColor']|noescape};
21-
--loginBackground: {$parameters['colors']['loginBackground']|noescape};
22-
--loginBackgroundInput: {$parameters['colors']['loginBackgroundInput']|noescape};
23-
--loginBackgroundInputFocus: {$parameters['colors']['loginBackgroundInputFocus']|noescape};
11+
--backgroundColor: {$colors['backgroundColor']|noescape};
12+
--dashboardAccentColor: {$colors['dashboardAccentColor']|noescape};
13+
--primaryColor: {$colors['primaryColor']|noescape};
14+
--primaryColorDark: {$colors['primaryColorDark']|noescape};
15+
--primaryColorDark20: {$colors['primaryColorDark20']|noescape};
16+
--secondaryColor: {$colors['secondaryColor']|noescape};
17+
--secondaryColorDark: {$colors['secondaryColorDark']|noescape};
18+
--secondaryColorDarker: {$colors['secondaryColorDarker']|noescape};
19+
--tertiaryColor: {$colors['ternaryColor']|noescape};
20+
--tertiaryTextColor: {$colors['ternaryTextColor']|noescape};
21+
--loginBackground: {$colors['loginBackground']|noescape};
22+
--loginBackgroundInput: {$colors['loginBackgroundInput']|noescape};
23+
--loginBackgroundInputFocus: {$colors['loginBackgroundInputFocus']|noescape};
2424
}
2525
</style>
2626
{/if}

src/UI/Presenters/BasePresenterTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected function beforeRender(): void
3636
$this->getTemplate()->loginPageLogoPath = $this->_fancyAdmin->getLoginPageLogoPath();
3737
$this->getTemplate()->hmr = $this->_fancyAdmin->getHmr();
3838
$this->getTemplate()->projectName = $this->_fancyAdmin->getProjectName();
39+
$this->getTemplate()->colors = $this->_fancyAdmin->getColors();
3940
}
4041

4142

0 commit comments

Comments
 (0)