Skip to content

Commit

Permalink
Allow to configure the global theme using the WebUI
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtronics committed Jun 24, 2024
1 parent 3e657a7 commit f88584e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
1 change: 0 additions & 1 deletion config/packages/twig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ twig:

globals:
default_currency: '%partdb.default_currency%'
global_theme: '%partdb.global_theme%'
allow_email_pw_reset: '%partdb.users.email_pw_reset%'
locale_menu: '%partdb.locale_menu%'
attachment_manager: '@App\Services\Attachments\AttachmentManager'
Expand Down
1 change: 0 additions & 1 deletion config/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ parameters:
# This is used as workaround for places where we can not access the settings directly (like the 2FA application names)
partdb.title: '%env(string:settings:customization:instanceName)%' # The title shown inside of Part-DB (e.g. in the navbar and on homepage)
partdb.default_currency: '%env(string:BASE_CURRENCY)%' # The currency that is used inside the DB (and is assumed when no currency is set). This can not be changed later, so be sure to set it the currency used in your country
partdb.global_theme: '' # The theme to use globally (see public/build/themes/ for choices, use name without .css). Set to '' for default bootstrap theme
partdb.locale_menu: ['en', 'de', 'it', 'fr', 'ru', 'ja', 'cs', 'da', 'zh'] # The languages that are shown in user drop down menu
partdb.enforce_change_comments_for: '%env(csv:ENFORCE_CHANGE_COMMENTS_FOR)%' # The actions for which a change comment is required (e.g. "part_edit", "part_create", etc.). If this is empty, change comments are not required at all.

Expand Down
8 changes: 8 additions & 0 deletions src/Settings/SystemSettings/CustomizationSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
namespace App\Settings\SystemSettings;

use App\Form\Type\RichTextEditorType;
use App\Form\Type\ThemeChoiceType;
use App\Validator\Constraints\ValidTheme;
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
Expand All @@ -48,4 +50,10 @@ class CustomizationSettings
)]
public ?string $banner = null;

#[SettingsParameter(
label: new TM("settings.system.customization.theme"),
formType: ThemeChoiceType::class, formOptions: ['placeholder' => false]
)]
#[ValidTheme]
public string $theme = 'bootstrap';
}
6 changes: 2 additions & 4 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@



{% if not app.user.theme is defined %}
{% set theme = global_theme %}
{% if app.user.theme is not defined or app.user.theme is null %}
{% set theme = settings_instance('customization').theme %}
{% else %}
{% set theme = app.user.theme %}
{% endif %}



{% if theme and theme in available_themes and encore_entry_exists('theme_' ~ theme) %}
{{ encore_entry_link_tags('theme_' ~ theme) }}
{% else %}
Expand Down
6 changes: 6 additions & 0 deletions translations/messages.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -12467,5 +12467,11 @@ Please note, that you can not impersonate a disabled user. If you try you will g
<target>Save removed data in log entries on element deletion</target>
</segment>
</unit>
<unit id="8665ItM" name="settings.system.customization.theme">
<segment>
<source>settings.system.customization.theme</source>
<target>Global theme</target>
</segment>
</unit>
</file>
</xliff>

0 comments on commit f88584e

Please sign in to comment.