From 8a10fec31de28393fcbbc4602d45bcb74add1afc Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 21 Oct 2021 13:44:30 +0100 Subject: [PATCH] [CONTROLLER][UserPanel] Make all fields in settings not required --- src/Controller/UserPanel.php | 8 +++++--- src/Util/Form/FormFields.php | 15 ++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Controller/UserPanel.php b/src/Controller/UserPanel.php index ffb7b26d78..b1791a5b25 100644 --- a/src/Controller/UserPanel.php +++ b/src/Controller/UserPanel.php @@ -41,6 +41,7 @@ use App\Core\DB\DB; use App\Core\Event; use App\Core\Form; use function App\Core\I18n\_m; +use App\Core\Log; use App\Entity\UserNotificationPrefs; use App\Util\Common; use App\Util\Exception\AuthenticationException; @@ -115,8 +116,8 @@ class UserPanel extends AbstractController $user = Common::user(); // TODO Add support missing settings $form = Form::create([ - ['outgoing_email', TextType::class, ['label' => _m('Outgoing email'), 'required' => true, 'help' => _m('Change the email we use to contact you')]], - ['incoming_email', TextType::class, ['label' => _m('Incoming email'), 'required' => true, 'help' => _m('Change the email you use to contact us (for posting, for instance)')]], + ['outgoing_email', TextType::class, ['label' => _m('Outgoing email'), 'required' => false, 'help' => _m('Change the email we use to contact you')]], + ['incoming_email', TextType::class, ['label' => _m('Incoming email'), 'required' => false, 'help' => _m('Change the email you use to contact us (for posting, for instance)')]], ['old_password', TextType::class, ['label' => _m('Old password'), 'required' => false, 'help' => _m('Enter your old password for verification'), 'attr' => ['placeholder' => '********']]], FormFields::repeated_password(['required' => false]), ['language', LocaleType::class, ['label' => _m('Language'), 'required' => false, 'help' => _m('Your preferred language')]], @@ -228,8 +229,9 @@ class UserPanel extends AbstractController // @codeCoverageIgnoreStart } catch (Exception $e) { // Somehow, the exception doesn't bubble up in phpunit - dd($data, $e); + // dd($data, $e); // @codeCoverageIgnoreEnd + Log::critical('Exception at ' . $e->getFile() . ':' . $e->getLine() . ': ' . $e->getMessage()); } } } diff --git a/src/Util/Form/FormFields.php b/src/Util/Form/FormFields.php index 8388a332a8..60808ee473 100644 --- a/src/Util/Form/FormFields.php +++ b/src/Util/Form/FormFields.php @@ -15,14 +15,14 @@ abstract class FormFields { public static function repeated_password(array $options = []): array { - return ['password', RepeatedType::class, - ['type' => PasswordType::class, + return [ + 'password', RepeatedType::class, + [ + 'type' => PasswordType::class, 'first_options' => [ - 'label' => _m('Password'), - 'label_attr' => ['class' => 'section-form-label'], - 'attr' => ['placeholder' => '********'], - 'required' => $options['required'] ?? true, - + 'label' => _m('Password'), + 'label_attr' => ['class' => 'section-form-label'], + 'attr' => ['placeholder' => '********'], 'constraints' => [ new NotBlank(['message' => _m('Please enter a password')]), new Length(['min' => Common::config('password', 'min_length'), 'minMessage' => _m(['Your password should be at least # characters'], ['count' => Common::config('password', 'min_length')]), @@ -37,6 +37,7 @@ abstract class FormFields 'help' => _m('Confirm your password.'), ], 'mapped' => false, + 'required' => $options['required'] ?? true, 'invalid_message' => _m('The password fields must match'), ], ];