Skip to content

Commit

Permalink
Merge pull request #164 from nucleos/form-type
Browse files Browse the repository at this point in the history
Move submit buttons to form definition
  • Loading branch information
core23 committed Dec 17, 2020
2 parents 7706d8a + 5c5e4b7 commit 67add15
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 44 deletions.
51 changes: 28 additions & 23 deletions src/Form/Type/ChangePasswordFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
Expand Down Expand Up @@ -46,31 +47,35 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$constraintsOptions['groups'] = [reset($options['validation_groups'])];
}

$builder->add('current_password', PasswordType::class, [
'label' => 'form.current_password',
'translation_domain' => 'NucleosUserBundle',
'mapped' => false,
'constraints' => [
new NotBlank(),
new UserPassword($constraintsOptions),
],
'attr' => [
'autocomplete' => 'current-password',
],
]);

$builder->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'options' => [
$builder
->add('current_password', PasswordType::class, [
'label' => 'form.current_password',
'translation_domain' => 'NucleosUserBundle',
'attr' => [
'autocomplete' => 'new-password',
'mapped' => false,
'constraints' => [
new NotBlank(),
new UserPassword($constraintsOptions),
],
],
'first_options' => ['label' => 'form.new_password'],
'second_options' => ['label' => 'form.new_password_confirmation'],
'invalid_message' => 'nucleos_user.password.mismatch',
]);
'attr' => [
'autocomplete' => 'current-password',
],
])
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'options' => [
'translation_domain' => 'NucleosUserBundle',
'attr' => [
'autocomplete' => 'new-password',
],
],
'first_options' => ['label' => 'form.new_password'],
'second_options' => ['label' => 'form.new_password_confirmation'],
'invalid_message' => 'nucleos_user.password.mismatch',
])
->add('save', SubmitType::class, [
'label' => 'change_password.submit',
])
;
}

public function configureOptions(OptionsResolver $resolver): void
Expand Down
28 changes: 17 additions & 11 deletions src/Form/Type/ResettingFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand All @@ -36,18 +37,23 @@ public function __construct(string $class)

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'options' => [
'translation_domain' => 'NucleosUserBundle',
'attr' => [
'autocomplete' => 'new-password',
$builder
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'options' => [
'translation_domain' => 'NucleosUserBundle',
'attr' => [
'autocomplete' => 'new-password',
],
],
],
'first_options' => ['label' => 'form.new_password'],
'second_options' => ['label' => 'form.new_password_confirmation'],
'invalid_message' => 'nucleos_user.password.mismatch',
]);
'first_options' => ['label' => 'form.new_password'],
'second_options' => ['label' => 'form.new_password_confirmation'],
'invalid_message' => 'nucleos_user.password.mismatch',
])
->add('save', SubmitType::class, [
'label' => 'resetting.reset.submit',
])
;
}

public function configureOptions(OptionsResolver $resolver): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@

{{ form_start(form, { 'action': path('nucleos_user_change_password'), 'attr': { 'class': 'nucleos_user_change_password' } }) }}
{{ form_widget(form) }}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary" value="{{ 'change_password.submit'|trans }}"/>
</div>
</div>
{{ form_end(form) }}
5 changes: 0 additions & 5 deletions src/Resources/views/Resetting/reset_content.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@

{{ form_start(form, { 'action': path('nucleos_user_resetting_reset', {'token': token}), 'attr': { 'class': 'nucleos_user_resetting_reset' } }) }}
{{ form_widget(form) }}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary" value="{{ 'resetting.reset.submit'|trans }}"/>
</div>
</div>
{{ form_end(form) }}

0 comments on commit 67add15

Please sign in to comment.