Skip to content

New extractor for constraints #450

@lukepass

Description

@lukepass

Hello, since the bundle doesn't automatically do this I created an extractor which should be able to get all the transactions from all the constraints:

php-translation/extractor#160

In the following example the extracted string would be Inserisci la nuova password..

class ChangePasswordFormType extends AbstractType
{
    /**
     * @param mixed[]                                           $options
     * @param FormBuilderInterface<FormBuilderInterface|string> $builder
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('plainPassword', RepeatedType::class, [
                'type' => PasswordType::class,
                'first_options' => [
                    'constraints' => [
                        new NotBlank([
                            'message' => 'Inserisci la nuova password.',
                        ]),
                        new Length([
                            'min' => 6,
                            'minMessage' => 'La nuova password deve essere di almeno {{ limit }} caratteri.',
                            // max length allowed by Symfony for security reasons
                            'max' => 4096,
                        ]),
                    ],
                    'label' => 'Nuova password',
                ],
                'second_options' => [
                    'label' => 'Ripeti password',
                ],
                'invalid_message' => 'Le due password devono corrispondere.',
                // Instead of being set onto the object directly,
                // this is read and encoded in the controller
                'mapped' => false,
            ])
        ;
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([]);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions