mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-12 00:47:45 +00:00
Implement form field for user profile to allow the update of a user's local preference
This commit is contained in:
@@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Notification\NotificationFlagManager;
|
||||
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
final class UpdateProfileCommand
|
||||
{
|
||||
@@ -23,11 +24,13 @@ final class UpdateProfileCommand
|
||||
public function __construct(
|
||||
#[PhonenumberConstraint]
|
||||
public ?PhoneNumber $phonenumber,
|
||||
#[Assert\Choice(choices: ['fr', 'nl'], message: 'Locale must be either "fr" or "nl"')]
|
||||
public string $locale = 'fr',
|
||||
) {}
|
||||
|
||||
public static function create(User $user, NotificationFlagManager $flagManager): self
|
||||
{
|
||||
$updateProfileCommand = new self($user->getPhonenumber());
|
||||
$updateProfileCommand = new self($user->getPhonenumber(), $user->getLocale());
|
||||
|
||||
foreach ($flagManager->getAllNotificationFlagProviders() as $provider) {
|
||||
$updateProfileCommand->setNotificationFlag(
|
||||
|
||||
@@ -18,6 +18,7 @@ final readonly class UpdateProfileCommandHandler
|
||||
public function updateProfile(User $user, UpdateProfileCommand $command): void
|
||||
{
|
||||
$user->setPhonenumber($command->phonenumber);
|
||||
$user->setLocale($command->locale);
|
||||
|
||||
foreach ($command->notificationFlags as $flag => $values) {
|
||||
$user->setNotificationImmediately($flag, $values['immediate_email']);
|
||||
|
||||
38
src/Bundle/ChillMainBundle/Form/Type/UserLocaleType.php
Normal file
38
src/Bundle/ChillMainBundle/Form/Type/UserLocaleType.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class UserLocaleType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'choices' => [
|
||||
'user.locale.choice.french' => 'fr',
|
||||
'user.locale.choice.dutch' => 'nl',
|
||||
],
|
||||
'placeholder' => 'user.locale.placeholder',
|
||||
'required' => true,
|
||||
'label' => 'user.locale.label',
|
||||
'help' => 'user.locale.help',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ namespace Chill\MainBundle\Form;
|
||||
use Chill\MainBundle\Action\User\UpdateProfile\UpdateProfileCommand;
|
||||
use Chill\MainBundle\Form\Type\ChillPhoneNumberType;
|
||||
use Chill\MainBundle\Form\Type\NotificationFlagsType;
|
||||
use Chill\MainBundle\Form\Type\UserLocaleType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
@@ -26,6 +27,7 @@ class UpdateProfileType extends AbstractType
|
||||
->add('phonenumber', ChillPhoneNumberType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
->add('locale', UserLocaleType::class)
|
||||
->add('notificationFlags', NotificationFlagsType::class)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,8 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{ form_row(form.locale) }}
|
||||
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<button type="submit" class="btn btn-save">{{ 'Save'|trans }}</button>
|
||||
|
||||
@@ -56,6 +56,13 @@ user:
|
||||
no job: Pas de métier assigné
|
||||
no scope: Pas de cercle assigné
|
||||
notification_preferences: Préférences pour mes notifications
|
||||
locale:
|
||||
label: Langue de communication
|
||||
help: Langue utilisée pour les notifications par email et autres communications.
|
||||
placeholder: Choisissez une langue
|
||||
choice:
|
||||
french: Français
|
||||
dutch: Nederlands
|
||||
|
||||
user_group:
|
||||
inactive: Inactif
|
||||
|
||||
@@ -46,6 +46,14 @@ No title: Geen titel
|
||||
User profile: Mijn gebruikersprofiel
|
||||
Phonenumber successfully updated!: Telefoonnummer bijgewerkt!
|
||||
|
||||
user:
|
||||
locale:
|
||||
label: Communicatietaal
|
||||
help: Taal gebruikt voor e-mailmeldingen en andere communicatie.
|
||||
placeholder: Kies een taal
|
||||
choice:
|
||||
french: Français
|
||||
dutch: Nederlands
|
||||
|
||||
Edit: Bewerken
|
||||
Update: Updaten
|
||||
|
||||
Reference in New Issue
Block a user