- fixed user settings database #9 - added dynamic user preferences #9 - added form to edit user preferences #9 - removed user language #7
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -31,8 +31,8 @@ class LanguageType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'choices' => array(
|
||||
Intl::getLocaleBundle()->getLocaleName('de', \Locale::getDefault()) => 'de',
|
||||
Intl::getLocaleBundle()->getLocaleName('en', \Locale::getDefault()) => 'en',
|
||||
Intl::getLocaleBundle()->getLocaleName('de', 'de') => 'de',
|
||||
Intl::getLocaleBundle()->getLocaleName('en', 'en') => 'en',
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
57
src/Form/Type/SkinType.php
Normal file
57
src/Form/Type/SkinType.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Custom form field type to select the themes skin.
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class SkinType extends AbstractType
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'required' => true,
|
||||
'choices' => array(
|
||||
'blue' => 'blue',
|
||||
'black' => 'black',
|
||||
'green' => 'green',
|
||||
'purple' => 'purple',
|
||||
'red' => 'red',
|
||||
'yellow' => 'yellow',
|
||||
'blue-light' => 'blue-light',
|
||||
'black-light' => 'black-light',
|
||||
'green-light' => 'green-light',
|
||||
'purple-light' => 'purple-light',
|
||||
'red-light' => 'red-light',
|
||||
'yellow-light' => 'yellow-light',
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
}
|
||||
64
src/Form/Type/UserPreferenceType.php
Normal file
64
src/Form/Type/UserPreferenceType.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Form\Type;
|
||||
|
||||
use App\Entity\UserPreference;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Custom form field type to edit a user preference.
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class UserPreferenceType extends AbstractType
|
||||
{
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->addEventListener(
|
||||
FormEvents::PRE_SET_DATA,
|
||||
function (FormEvent $event) {
|
||||
/** @var UserPreference $preference */
|
||||
$preference = $event->getData();
|
||||
|
||||
if ($preference instanceof UserPreference) {
|
||||
// prevents unconfigured values from showing up in the form
|
||||
if ($preference->getType() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->getForm()->add('value', $preference->getType(), [
|
||||
'label' => 'label.' . $preference->getName(),
|
||||
'constraints' => $preference->getConstraints()
|
||||
]);
|
||||
}
|
||||
}
|
||||
);
|
||||
$builder->add('name', HiddenType::class);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => UserPreference::class,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -37,8 +37,8 @@ class UserCreateType extends UserEditType
|
||||
->add('plainPassword', RepeatedType::class, [
|
||||
'required' => true,
|
||||
'type' => PasswordType::class,
|
||||
'first_options' => array('label' => 'security.label.password'),
|
||||
'second_options' => array('label' => 'security.label.password_repeat'),
|
||||
'first_options' => array('label' => 'label.password'),
|
||||
'second_options' => array('label' => 'label.password_repeat'),
|
||||
]);
|
||||
|
||||
parent::buildForm($builder, $options);
|
||||
|
||||
@@ -52,10 +52,6 @@ class UserEditType extends AbstractType
|
||||
->add('email', TextType::class, [
|
||||
'label' => 'label.email',
|
||||
])
|
||||
// string - length 5
|
||||
->add('language', LanguageType::class, [
|
||||
'label' => 'label.language',
|
||||
])
|
||||
// boolean
|
||||
->add('active', YesNoType::class, [
|
||||
'label' => 'label.active',
|
||||
|
||||
@@ -34,8 +34,8 @@ class UserPasswordType extends AbstractType
|
||||
$builder
|
||||
->add('plainPassword', RepeatedType::class, [
|
||||
'type' => PasswordType::class,
|
||||
'first_options' => array('label' => 'security.label.password'),
|
||||
'second_options' => array('label' => 'security.label.password_repeat'),
|
||||
'first_options' => array('label' => 'label.password'),
|
||||
'second_options' => array('label' => 'label.password_repeat'),
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
56
src/Form/UserPreferencesForm.php
Normal file
56
src/Form/UserPreferencesForm.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\Type\UserPreferenceType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Defines the form used to edit the user preferences.
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class UserPreferencesForm extends AbstractType
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('preferences', CollectionType::class, [
|
||||
'entry_type' => UserPreferenceType::class,
|
||||
'entry_options' => array('label' => false),
|
||||
'allow_add' => false,
|
||||
'allow_delete' => false,
|
||||
'label' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => User::class,
|
||||
'csrf_protection' => true,
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_token_id' => 'edit_user_preferences',
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user