mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Allow to configure which themes should be available via parameters.yaml
This commit is contained in:
parent
489b3e2c21
commit
08c97282a3
8 changed files with 99 additions and 26 deletions
|
@ -18,6 +18,7 @@ twig:
|
||||||
sidebar_items: '%partdb.sidebar.items%'
|
sidebar_items: '%partdb.sidebar.items%'
|
||||||
sidebar_tree_updater: '@App\Services\Trees\SidebarTreeUpdater'
|
sidebar_tree_updater: '@App\Services\Trees\SidebarTreeUpdater'
|
||||||
avatar_helper: '@App\Services\UserSystem\UserAvatarHelper'
|
avatar_helper: '@App\Services\UserSystem\UserAvatarHelper'
|
||||||
|
available_themes: '%partdb.available_themes%'
|
||||||
|
|
||||||
when@test:
|
when@test:
|
||||||
twig:
|
twig:
|
||||||
|
|
|
@ -55,6 +55,37 @@ parameters:
|
||||||
######################################################################################################################
|
######################################################################################################################
|
||||||
partdb.demo_mode: '%env(bool:DEMO_MODE)%' # If set to true, all potentially dangerous things are disabled (like changing passwords of the own user)
|
partdb.demo_mode: '%env(bool:DEMO_MODE)%' # If set to true, all potentially dangerous things are disabled (like changing passwords of the own user)
|
||||||
|
|
||||||
|
# Set the themes from which the user can choose from in the settings.
|
||||||
|
# Themes commented here by default, are not really usable, because of display problems. Enable them at your own risk!
|
||||||
|
partdb.available_themes:
|
||||||
|
- bootstrap
|
||||||
|
- cerulean
|
||||||
|
- cosmo
|
||||||
|
- cyborg
|
||||||
|
- darkly
|
||||||
|
- flatly
|
||||||
|
- journal
|
||||||
|
- litera
|
||||||
|
- lumen
|
||||||
|
- lux
|
||||||
|
#- materia
|
||||||
|
- minty
|
||||||
|
#- morph
|
||||||
|
#- pulse
|
||||||
|
#- quartz
|
||||||
|
- sandstone
|
||||||
|
- simplex
|
||||||
|
- sketchy
|
||||||
|
- slate
|
||||||
|
- solar
|
||||||
|
- spacelab
|
||||||
|
- superhero
|
||||||
|
- united
|
||||||
|
#- vapor
|
||||||
|
- yeti
|
||||||
|
- zephyr
|
||||||
|
|
||||||
|
|
||||||
######################################################################################################################
|
######################################################################################################################
|
||||||
# Env default values
|
# Env default values
|
||||||
######################################################################################################################
|
######################################################################################################################
|
||||||
|
|
|
@ -186,6 +186,10 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
$use_gravatar: '%partdb.users.use_gravatar%'
|
$use_gravatar: '%partdb.users.use_gravatar%'
|
||||||
|
|
||||||
|
App\Form\Type\ThemeChoiceType:
|
||||||
|
arguments:
|
||||||
|
$available_themes: '%partdb.available_themes%'
|
||||||
|
|
||||||
|
|
||||||
####################################################################################################################
|
####################################################################################################################
|
||||||
# Label system
|
# Label system
|
||||||
|
|
|
@ -68,10 +68,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
||||||
*/
|
*/
|
||||||
public const ID_ANONYMOUS = 1;
|
public const ID_ANONYMOUS = 1;
|
||||||
|
|
||||||
public const AVAILABLE_THEMES = ['bootstrap', 'cerulean', 'cosmo', 'cyborg', 'darkly', 'flatly', 'journal',
|
|
||||||
'litera', 'lumen', 'lux', 'materia', 'minty', 'morph', 'pulse', 'quartz', 'sandstone', 'simplex', 'sketchy', 'slate', 'solar',
|
|
||||||
'spacelab', 'superhero', 'united', 'vapor', 'yeti', 'zephyr'];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool Determines if the user is disabled (user can not log in)
|
* @var bool Determines if the user is disabled (user can not log in)
|
||||||
* @ORM\Column(type="boolean")
|
* @ORM\Column(type="boolean")
|
||||||
|
|
58
src/Form/Type/ThemeChoiceType.php
Normal file
58
src/Form/Type/ThemeChoiceType.php
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Form\Type;
|
||||||
|
|
||||||
|
use App\Entity\UserSystem\User;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class ThemeChoiceType extends AbstractType
|
||||||
|
{
|
||||||
|
private array $available_themes;
|
||||||
|
|
||||||
|
public function __construct(array $available_themes)
|
||||||
|
{
|
||||||
|
$this->available_themes = $available_themes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getParent()
|
||||||
|
{
|
||||||
|
return ChoiceType::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'choices' => $this->available_themes,
|
||||||
|
'choice_label' => static function ($entity, $key, $value) {
|
||||||
|
return $value;
|
||||||
|
},
|
||||||
|
'attr' => [
|
||||||
|
'data-controller' => 'elements--selectpicker',
|
||||||
|
'title' => 'selectpicker.nothing_selected',
|
||||||
|
],
|
||||||
|
'choice_translation_domain' => false,
|
||||||
|
'placeholder' => 'user_settings.theme.placeholder'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ use App\Form\Permissions\PermissionsType;
|
||||||
use App\Form\Type\CurrencyEntityType;
|
use App\Form\Type\CurrencyEntityType;
|
||||||
use App\Form\Type\MasterPictureAttachmentType;
|
use App\Form\Type\MasterPictureAttachmentType;
|
||||||
use App\Form\Type\StructuralEntityType;
|
use App\Form\Type\StructuralEntityType;
|
||||||
|
use App\Form\Type\ThemeChoiceType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
@ -151,18 +152,8 @@ class UserAdminForm extends AbstractType
|
||||||
'preferred_choices' => ['Europe/Berlin'],
|
'preferred_choices' => ['Europe/Berlin'],
|
||||||
'disabled' => !$this->security->isGranted('change_user_settings', $entity),
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity),
|
||||||
])
|
])
|
||||||
->add('theme', ChoiceType::class, [
|
->add('theme', ThemeChoiceType::class, [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'choices' => User::AVAILABLE_THEMES,
|
|
||||||
'choice_label' => static function ($entity, $key, $value) {
|
|
||||||
return $value;
|
|
||||||
},
|
|
||||||
'attr' => [
|
|
||||||
'data-controller' => 'elements--selectpicker',
|
|
||||||
'title' => 'selectpicker.nothing_selected',
|
|
||||||
],
|
|
||||||
'choice_translation_domain' => false,
|
|
||||||
'placeholder' => 'user_settings.theme.placeholder',
|
|
||||||
'label' => 'user.theme.label',
|
'label' => 'user.theme.label',
|
||||||
'disabled' => !$this->security->isGranted('change_user_settings', $entity),
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity),
|
||||||
])
|
])
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace App\Form;
|
||||||
|
|
||||||
use App\Entity\UserSystem\User;
|
use App\Entity\UserSystem\User;
|
||||||
use App\Form\Type\CurrencyEntityType;
|
use App\Form\Type\CurrencyEntityType;
|
||||||
|
use App\Form\Type\ThemeChoiceType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\Event\PreSetDataEvent;
|
use Symfony\Component\Form\Event\PreSetDataEvent;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
@ -114,18 +115,9 @@ class UserSettingsType extends AbstractType
|
||||||
'label' => 'user.timezone.label',
|
'label' => 'user.timezone.label',
|
||||||
'preferred_choices' => ['Europe/Berlin'],
|
'preferred_choices' => ['Europe/Berlin'],
|
||||||
])
|
])
|
||||||
->add('theme', ChoiceType::class, [
|
->add('theme', ThemeChoiceType::class, [
|
||||||
'disabled' => $this->demo_mode,
|
'disabled' => $this->demo_mode,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'attr' => [
|
|
||||||
'data-controller' => 'elements--selectpicker',
|
|
||||||
],
|
|
||||||
'choice_translation_domain' => false,
|
|
||||||
'choices' => User::AVAILABLE_THEMES,
|
|
||||||
'choice_label' => static function ($entity, $key, $value) {
|
|
||||||
return $value;
|
|
||||||
},
|
|
||||||
'placeholder' => 'user_settings.theme.placeholder',
|
|
||||||
'label' => 'user.theme.label',
|
'label' => 'user.theme.label',
|
||||||
])
|
])
|
||||||
->add('currency', CurrencyEntityType::class, [
|
->add('currency', CurrencyEntityType::class, [
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% if theme and theme in constant('App\\Entity\\UserSystem\\User::AVAILABLE_THEMES') and encore_entry_exists('theme_' ~ theme) %}
|
{% if theme and theme in available_themes and encore_entry_exists('theme_' ~ theme) %}
|
||||||
{{ encore_entry_link_tags('theme_' ~ theme) }}
|
{{ encore_entry_link_tags('theme_' ~ theme) }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ encore_entry_link_tags('theme_bootstrap') }}
|
{{ encore_entry_link_tags('theme_bootstrap') }}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue