Allow to configure which themes should be available via parameters.yaml

This commit is contained in:
Jan Böhmer 2023-02-01 23:15:02 +01:00
parent 489b3e2c21
commit 08c97282a3
8 changed files with 99 additions and 26 deletions

View file

@ -68,10 +68,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/
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)
* @ORM\Column(type="boolean")

View 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'
]);
}
}

View file

@ -30,6 +30,7 @@ use App\Form\Permissions\PermissionsType;
use App\Form\Type\CurrencyEntityType;
use App\Form\Type\MasterPictureAttachmentType;
use App\Form\Type\StructuralEntityType;
use App\Form\Type\ThemeChoiceType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -151,18 +152,8 @@ class UserAdminForm extends AbstractType
'preferred_choices' => ['Europe/Berlin'],
'disabled' => !$this->security->isGranted('change_user_settings', $entity),
])
->add('theme', ChoiceType::class, [
->add('theme', ThemeChoiceType::class, [
'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',
'disabled' => !$this->security->isGranted('change_user_settings', $entity),
])

View file

@ -24,6 +24,7 @@ namespace App\Form;
use App\Entity\UserSystem\User;
use App\Form\Type\CurrencyEntityType;
use App\Form\Type\ThemeChoiceType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Event\PreSetDataEvent;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -114,18 +115,9 @@ class UserSettingsType extends AbstractType
'label' => 'user.timezone.label',
'preferred_choices' => ['Europe/Berlin'],
])
->add('theme', ChoiceType::class, [
->add('theme', ThemeChoiceType::class, [
'disabled' => $this->demo_mode,
'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',
])
->add('currency', CurrencyEntityType::class, [