vendor/symfony/form/Extension/Core/Type/PasswordType.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Form\Extension\Core\Type;
  11. use Symfony\Component\Form\AbstractType;
  12. use Symfony\Component\Form\FormInterface;
  13. use Symfony\Component\Form\FormView;
  14. use Symfony\Component\OptionsResolver\Options;
  15. use Symfony\Component\OptionsResolver\OptionsResolver;
  16. class PasswordType extends AbstractType
  17. {
  18.     /**
  19.      * {@inheritdoc}
  20.      */
  21.     public function buildView(FormView $viewFormInterface $form, array $options)
  22.     {
  23.         if ($options['always_empty'] || !$form->isSubmitted()) {
  24.             $view->vars['value'] = '';
  25.         }
  26.     }
  27.     /**
  28.      * {@inheritdoc}
  29.      */
  30.     public function configureOptions(OptionsResolver $resolver)
  31.     {
  32.         $resolver->setDefaults([
  33.             'always_empty' => true,
  34.             'trim' => false,
  35.             'invalid_message' => function (Options $options$previousValue) {
  36.                 return ($options['legacy_error_messages'] ?? true)
  37.                     ? $previousValue
  38.                     'The password is invalid.';
  39.             },
  40.         ]);
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function getParent()
  46.     {
  47.         return TextType::class;
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function getBlockPrefix()
  53.     {
  54.         return 'password';
  55.     }
  56. }