[CONTROLLER][UserPanel] Make all fields in settings not required

This commit is contained in:
Hugo Sales 2021-10-21 13:44:30 +01:00 committed by Diogo Peralta Cordeiro
parent 2694d83ae4
commit 8a10fec31d
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
2 changed files with 13 additions and 10 deletions

View File

@ -41,6 +41,7 @@ use App\Core\DB\DB;
use App\Core\Event; use App\Core\Event;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Core\Log;
use App\Entity\UserNotificationPrefs; use App\Entity\UserNotificationPrefs;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\AuthenticationException; use App\Util\Exception\AuthenticationException;
@ -115,8 +116,8 @@ class UserPanel extends AbstractController
$user = Common::user(); $user = Common::user();
// TODO Add support missing settings // TODO Add support missing settings
$form = Form::create([ $form = Form::create([
['outgoing_email', TextType::class, ['label' => _m('Outgoing email'), 'required' => true, 'help' => _m('Change the email we use to contact you')]], ['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' => true, 'help' => _m('Change the email you use to contact us (for posting, for instance)')]], ['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' => '********']]], ['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]), FormFields::repeated_password(['required' => false]),
['language', LocaleType::class, ['label' => _m('Language'), 'required' => false, 'help' => _m('Your preferred language')]], ['language', LocaleType::class, ['label' => _m('Language'), 'required' => false, 'help' => _m('Your preferred language')]],
@ -228,8 +229,9 @@ class UserPanel extends AbstractController
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
} catch (Exception $e) { } catch (Exception $e) {
// Somehow, the exception doesn't bubble up in phpunit // Somehow, the exception doesn't bubble up in phpunit
dd($data, $e); // dd($data, $e);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
Log::critical('Exception at ' . $e->getFile() . ':' . $e->getLine() . ': ' . $e->getMessage());
} }
} }
} }

View File

@ -15,14 +15,14 @@ abstract class FormFields
{ {
public static function repeated_password(array $options = []): array public static function repeated_password(array $options = []): array
{ {
return ['password', RepeatedType::class, return [
['type' => PasswordType::class, 'password', RepeatedType::class,
[
'type' => PasswordType::class,
'first_options' => [ 'first_options' => [
'label' => _m('Password'), 'label' => _m('Password'),
'label_attr' => ['class' => 'section-form-label'], 'label_attr' => ['class' => 'section-form-label'],
'attr' => ['placeholder' => '********'], 'attr' => ['placeholder' => '********'],
'required' => $options['required'] ?? true,
'constraints' => [ 'constraints' => [
new NotBlank(['message' => _m('Please enter a password')]), 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')]), 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.'), 'help' => _m('Confirm your password.'),
], ],
'mapped' => false, 'mapped' => false,
'required' => $options['required'] ?? true,
'invalid_message' => _m('The password fields must match'), 'invalid_message' => _m('The password fields must match'),
], ],
]; ];