Skip to content

Commit

Permalink
feat: Use Twig global for main_color variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Aug 29, 2024
1 parent 9c82755 commit 106b564
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ private function prepareAndHandleCustomFormAssignation(
'fields' => $customFormsEntity->getFields(),
'head' => [
'siteTitle' => $this->settingsBag->get('site_name'),
'mainColor' => $this->settingsBag->get('main_color'),
]
];
$helper = $this->customFormHelperFactory->createHelper($customFormsEntity);
Expand Down
7 changes: 1 addition & 6 deletions lib/RoadizCoreBundle/src/Mailer/EmailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,12 @@ public function renderPlainTextEmailBody(): string
}

/**
* Added mainColor and headerImageSrc assignation
* to display email header.
* Added headerImageSrc assignation to display email header.
*
* @return $this
*/
public function appendWebsiteIcon(): static
{
if (empty($this->assignation['mainColor']) && null !== $this->settingsBag) {
$this->assignation['mainColor'] = $this->settingsBag->get('main_color');
}

if (empty($this->assignation['headerImageSrc']) && null !== $this->settingsBag) {
$adminImage = $this->settingsBag->getDocument('admin_image');
if ($adminImage instanceof DocumentInterface && null !== $this->documentUrlGenerator) {
Expand Down
1 change: 1 addition & 0 deletions lib/RoadizCoreBundle/src/TwigExtension/RoadizExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function getGlobals(): array
'nodeTypes' => $this->nodeTypesBag,
],
'chroot_resolver' => $this->chrootResolver,
'main_color' => $this->settingsBag->get('main_color'),
'meta' => [
'siteName' => $this->settingsBag->get('site_name'),
'siteCopyright' => $this->settingsBag->get('site_copyright'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
{% include '@RoadizRozier/admin/meta-icon.html.twig' %}
{# CSS scripts inclusions / Using webpack #}
{% include '@RoadizRozier/partials/css-inject.html.twig' %}
{% if head.mainColor %}
{% if main_color %}
<style>
:root {
--rz-accent-color: {{ head.mainColor|raw }};
--rz-accent-color: {{ main_color|raw }};
--rz-accent-color-lighter: color-mix(in srgb, var(--rz-accent-color) var(--color-light-mix), white);
--rz-accent-color-darker: color-mix(in srgb, var(--rz-accent-color) var(--color-darker-mix), black);
--rz-accent-color-darkest: color-mix(in srgb, var(--rz-accent-color) var(--color-darkest-mix), black);
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/templates/email/base_email.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<table class="main" width="100%" cellpadding="0" cellspacing="0">
{% if headerImageSrc is defined %}
<tr>
<td class="header-image-wrap aligncenter"{% if mainColor is defined %}style="background-color: {{ mainColor }};"{% endif %}>
<td class="header-image-wrap aligncenter"{% if main_color is defined %}style="background-color: {{ main_color }};"{% endif %}>
<img class="header-image" src="{{ headerImageSrc }}" alt="{{ title }}" />
</td>
</tr>
Expand Down
2 changes: 0 additions & 2 deletions lib/RoadizRozierBundle/src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function login(Request $request, AuthenticationUtils $authenticationUtils
'themeServices' => $this->rozierServiceRegistry,
'head' => [
'siteTitle' => $this->settingsBag->get('site_name') . ' backstage',
'mainColor' => $this->settingsBag->get('main_color'),
]
];

Expand Down Expand Up @@ -77,7 +76,6 @@ public function requestLoginLink(
'themeServices' => $this->rozierServiceRegistry,
'head' => [
'siteTitle' => $this->settingsBag->get('site_name') . ' backstage',
'mainColor' => $this->settingsBag->get('main_color'),
]
];
// check if form is submitted
Expand Down
4 changes: 2 additions & 2 deletions lib/RoadizRozierBundle/templates/simple.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
{% include '@RoadizRozier/admin/meta-icon.html.twig' %}
{# CSS scripts inclusions / Using webpack #}
{% include '@RoadizRozier/partials/css-inject.html.twig' %}
{% if head.mainColor %}
{% if main_color %}
<style>
:root {
--rz-accent-color: {{ head.mainColor|raw }};
--rz-accent-color: {{ main_color|raw }};
--rz-accent-color-lighter: color-mix(in srgb, var(--rz-accent-color) var(--color-light-mix), white);
--rz-accent-color-darker: color-mix(in srgb, var(--rz-accent-color) var(--color-darker-mix), black);
--rz-accent-color-darkest: color-mix(in srgb, var(--rz-accent-color) var(--color-darkest-mix), black);
Expand Down
12 changes: 6 additions & 6 deletions lib/Rozier/src/Resources/views/admin/meta-icon.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
<link rel="icon" type="image/png" sizes="32x32" href="{{ asset('assets/img/favicon-32x32.png', 'Rozier') }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ asset('assets/img/favicon-16x16.png', 'Rozier') }}">
{% endif %}
{% if themeServices.adminImage and themeServices.adminImage.mimeType == 'image/svg+xml' and head.mainColor %}
<link rel="mask-icon" href="{{ themeServices.adminImage|url({absolute: true}) }}" color="{{ head.mainColor }}">
{% if themeServices.adminImage and themeServices.adminImage.mimeType == 'image/svg+xml' and main_color %}
<link rel="mask-icon" href="{{ themeServices.adminImage|url({absolute: true}) }}" color="{{ main_color }}">
{% endif %}
{% if head.mainColor %}
<meta name="msapplication-TileColor" content="{{ head.mainColor }}">
<meta name="apple-mobile-web-app-status-bar-style" content="{{ head.mainColor }}">
<meta name="theme-color" content="{{ head.mainColor }}">
{% if main_color %}
<meta name="msapplication-TileColor" content="{{ main_color }}">
<meta name="apple-mobile-web-app-status-bar-style" content="{{ main_color }}">
<meta name="theme-color" content="{{ main_color }}">
{% else %}
<meta name="msapplication-TileColor" content="#2d89ef">
<meta name="apple-mobile-web-app-status-bar-style" content="#808080">
Expand Down
6 changes: 3 additions & 3 deletions lib/Rozier/src/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
{# CSS scripts inclusions / Using webpack #}
{% include '@RoadizRozier/partials/css-inject.html.twig' %}

{% if head.mainColor %}
{% if main_color %}
<style>
:root {
--rz-accent-color: {{ head.mainColor|raw }};
--rz-accent-color: {{ main_color|raw }};
--rz-accent-color-lighter: color-mix(in srgb, var(--rz-accent-color) var(--color-light-mix), white);
--rz-accent-color-darker: color-mix(in srgb, var(--rz-accent-color) var(--color-darker-mix), black);
--rz-accent-color-darkest: color-mix(in srgb, var(--rz-accent-color) var(--color-darkest-mix), black);
Expand Down Expand Up @@ -94,7 +94,7 @@
'baseUrl': '{{ head.baseUrl }}',
'resourcesUrl': '{{ asset('', 'Rozier') }}',
'ajaxToken': '{{ head.ajaxToken }}',
'mainColor': '{{ head.mainColor }}',
'mainColor': '{{ main_color }}',
'mapsStyle': {% if head.mapsStyle %}{{ head.mapsStyle|raw }}{% else %}[]{% endif %},
'leafletMapTileUrl': '{{ bags.settings.get('leaflet_map_tile_url')|default('https://{s}.tile.osm.org/{z}/{x}/{y}.png') }}',
'googleClientId': '{{ head.googleClientId }}',
Expand Down
4 changes: 2 additions & 2 deletions lib/Rozier/src/Resources/views/css/mainColor.css.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% if head.mainColor %}
{% if main_color %}
:root {
--rz-accent-color: {{ head.mainColor|raw }};
--rz-accent-color: {{ main_color|raw }};
--rz-accent-color-lighter: color-mix(in srgb, var(--rz-accent-color) 70%, white);
--rz-accent-color-darker: color-mix(in srgb, var(--rz-accent-color) 90%, black);
--rz-accent-color-darkest: color-mix(in srgb, var(--rz-accent-color) 80%, black);
Expand Down
1 change: 0 additions & 1 deletion lib/Rozier/src/RozierApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public function prepareBaseAssignation(): static
$this->assignation['head']['backDevMode'] = false;
$this->assignation['head']['siteTitle'] = $this->getSettingsBag()->get('site_name') . ' backstage';
$this->assignation['head']['mapsLocation'] = $this->getSettingsBag()->get('maps_default_location') ? $this->getSettingsBag()->get('maps_default_location') : null;
$this->assignation['head']['mainColor'] = $this->getSettingsBag()->get('main_color');
$this->assignation['head']['googleClientId'] = $this->getSettingsBag()->get('google_client_id', "");
$this->assignation['head']['themeName'] = static::$themeName;
$this->assignation['head']['ajaxToken'] = $tokenManager->getToken(static::AJAX_TOKEN_INTENTION);
Expand Down

0 comments on commit 106b564

Please sign in to comment.