feature #30931 [Form] Improve invalid messages for form types (hiddewie)

This PR was merged into the 5.2-dev branch.

Discussion
----------

[Form] Improve invalid messages for form types

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #27142, #5946
| License       | MIT
| Doc PR        | TODO

This merge request is a continuation of https://github.com/symfony/symfony/pull/27142.

Changes done here:

* rebased on master
* made the error messages friendlier

Commits
-------

8728927a22 Improve invalid messages for form types
This commit is contained in:
Christian Flothmann 2020-07-10 16:13:16 +02:00
commit dfc32678c1
93 changed files with 1828 additions and 27 deletions

View File

@ -189,6 +189,18 @@ class Configuration implements ConfigurationInterface
->scalarNode('field_name')->defaultValue('_token')->end()
->end()
->end()
// to be set to false in Symfony 6.0
->booleanNode('legacy_error_messages')
->defaultTrue()
->validate()
->ifTrue()
->then(function ($v) {
@trigger_error('Since symfony/framework-bundle 5.2: Setting the "framework.form.legacy_error_messages" option to "true" is deprecated. It will have no effect as of Symfony 6.0.', E_USER_DEPRECATED);
return $v;
})
->end()
->end()
->end()
->end()
->end()

View File

@ -514,6 +514,8 @@ class FrameworkExtension extends Extension
{
$loader->load('form.php');
$container->getDefinition('form.type_extension.form.validator')->setArgument(1, $config['form']['legacy_error_messages']);
if (null === $config['form']['csrf_protection']['enabled']) {
$config['form']['csrf_protection']['enabled'] = $config['csrf_protection']['enabled'];
}

View File

@ -52,6 +52,7 @@
<xsd:element name="csrf-protection" type="form_csrf_protection" minOccurs="0" maxOccurs="1" />
</xsd:all>
<xsd:attribute name="enabled" type="xsd:boolean" />
<xsd:attribute name="legacy-error-messages" type="xsd:boolean" />
</xsd:complexType>
<xsd:complexType name="form_csrf_protection">

View File

@ -354,6 +354,7 @@ class ConfigurationTest extends TestCase
'enabled' => null, // defaults to csrf_protection.enabled
'field_name' => '_token',
],
'legacy_error_messages' => true,
],
'esi' => ['enabled' => false],
'ssi' => ['enabled' => false],

View File

@ -2,7 +2,9 @@
$container->loadFromExtension('framework', [
'csrf_protection' => true,
'form' => true,
'form' => [
'legacy_error_messages' => false,
],
'session' => [
'handler_id' => null,
],

View File

@ -0,0 +1,7 @@
<?php
$container->loadFromExtension('framework', [
'form' => [
'legacy_error_messages' => true,
],
]);

View File

@ -5,5 +5,6 @@ $container->loadFromExtension('framework', [
'csrf_protection' => [
'enabled' => false,
],
'legacy_error_messages' => false,
],
]);

View File

@ -8,6 +8,7 @@ $container->loadFromExtension('framework', [
'csrf_protection' => [
'field_name' => '_csrf',
],
'legacy_error_messages' => false,
],
'http_method_override' => false,
'esi' => [

View File

@ -8,7 +8,7 @@
<framework:config>
<framework:csrf-protection />
<framework:form />
<framework:form legacy-error-messages="false" />
<framework:session />
</framework:config>
</container>

View File

@ -9,6 +9,6 @@
<framework:config>
<framework:csrf-protection field-name="_custom" />
<framework:session />
<framework:form />
<framework:form legacy-error-messages="false" />
</framework:config>
</container>

View File

@ -8,7 +8,7 @@
<framework:config>
<framework:csrf-protection field-name="_custom_form" />
<framework:form />
<framework:form legacy-error-messages="false" />
<framework:session />
</framework:config>
</container>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:form legacy-error-messages="true" />
</framework:config>
</container>

View File

@ -7,7 +7,7 @@
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:form enabled="true">
<framework:form enabled="true" legacy-error-messages="false">
<framework:csrf-protection enabled="false" />
</framework:form>
</framework:config>

View File

@ -8,7 +8,7 @@
<framework:config secret="s3cr3t" ide="file%%link%%format" default-locale="fr" http-method-override="false">
<framework:csrf-protection />
<framework:form>
<framework:form legacy-error-messages="false">
<framework:csrf-protection field-name="_csrf"/>
</framework:form>
<framework:esi enabled="true" />

View File

@ -1,5 +1,6 @@
framework:
secret: s3cr3t
csrf_protection: ~
form: ~
form:
legacy_error_messages: false
session: ~

View File

@ -0,0 +1,3 @@
framework:
form:
legacy_error_messages: true

View File

@ -2,3 +2,4 @@ framework:
form:
csrf_protection:
enabled: false
legacy_error_messages: false

View File

@ -5,6 +5,7 @@ framework:
form:
csrf_protection:
field_name: _csrf
legacy_error_messages: false
http_method_override: false
esi:
enabled: true

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
use Doctrine\Common\Annotations\Annotation;
use Psr\Log\LoggerAwareInterface;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyMessage;
@ -57,6 +58,8 @@ use Symfony\Component\Workflow;
abstract class FrameworkExtensionTest extends TestCase
{
use ExpectDeprecationTrait;
private static $containerCache = [];
abstract protected function loadFromFile(ContainerBuilder $container, $file);
@ -1015,6 +1018,16 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertFalse($container->getParameter('form.type_extension.csrf.enabled'));
}
/**
* @group legacy
*/
public function testFormsWithoutImprovedValidationMessages()
{
$this->expectDeprecation('Since symfony/framework-bundle 5.2: Setting the "framework.form.legacy_error_messages" option to "true" is deprecated. It will have no effect as of Symfony 6.0.');
$this->createContainerFromFile('form_legacy_messages');
}
public function testStopwatchEnabledWithDebugModeEnabled()
{
$container = $this->createContainerFromFile('default_config', [

View File

@ -3,7 +3,9 @@ framework:
router: { resource: "%kernel.project_dir%/%kernel.test_case%/routing.yml", utf8: true }
validation: { enabled: true, enable_annotations: true }
csrf_protection: true
form: true
form:
enabled: true
legacy_error_messages: false
test: true
default_locale: en
session:

View File

@ -3,7 +3,9 @@ framework:
router: { resource: "%kernel.project_dir%/%kernel.test_case%/routing.yml", utf8: true }
validation: { enabled: true, enable_annotations: true }
csrf_protection: true
form: true
form:
enabled: true
legacy_error_messages: false
test: ~
default_locale: en
session:

View File

@ -4,7 +4,9 @@ framework:
validation: { enabled: true, enable_annotations: true }
assets: ~
csrf_protection: true
form: true
form:
enabled: true
legacy_error_messages: false
test: ~
default_locale: en
session:

View File

@ -37,7 +37,7 @@
"symfony/dom-crawler": "^4.4|^5.0",
"symfony/expression-language": "^4.4|^5.0",
"symfony/form": "^4.4|^5.0",
"symfony/framework-bundle": "^4.4|^5.0",
"symfony/framework-bundle": "^5.2",
"symfony/process": "^4.4|^5.0",
"symfony/serializer": "^4.4|^5.0",
"symfony/translation": "^4.4|^5.0",

View File

@ -51,14 +51,15 @@ class TransformationFailureListener implements EventSubscriberInterface
}
$clientDataAsString = is_scalar($form->getViewData()) ? (string) $form->getViewData() : get_debug_type($form->getViewData());
$messageTemplate = 'The value {{ value }} is not valid.';
$messageTemplate = $form->getConfig()->getOption('invalid_message', 'The value {{ value }} is not valid.');
$messageParameters = array_replace(['{{ value }}' => $clientDataAsString], $form->getConfig()->getOption('invalid_message_parameters', []));
if (null !== $this->translator) {
$message = $this->translator->trans($messageTemplate, ['{{ value }}' => $clientDataAsString]);
$message = $this->translator->trans($messageTemplate, $messageParameters);
} else {
$message = strtr($messageTemplate, ['{{ value }}' => $clientDataAsString]);
$message = strtr($messageTemplate, $messageParameters);
}
$form->addError(new FormError($message, $messageTemplate, ['{{ value }}' => $clientDataAsString], null, $form->getTransformationFailure()));
$form->addError(new FormError($message, $messageTemplate, $messageParameters, null, $form->getTransformationFailure()));
}
}

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class BirthdayType extends AbstractType
@ -21,7 +22,14 @@ class BirthdayType extends AbstractType
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('years', range((int) date('Y') - 120, date('Y')));
$resolver->setDefaults([
'years' => range((int) date('Y') - 120, date('Y')),
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please enter a valid birthdate.';
},
]);
$resolver->setAllowedTypes('years', 'array');
}

View File

@ -16,6 +16,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransfo
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CheckboxType extends AbstractType
@ -60,6 +61,11 @@ class CheckboxType extends AbstractType
'empty_data' => $emptyData,
'compound' => false,
'false_values' => [null],
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'The checkbox has an invalid value.';
},
'is_empty_callback' => static function ($modelData): bool {
return false === $modelData;
},

View File

@ -338,6 +338,11 @@ class ChoiceType extends AbstractType
'data_class' => null,
'choice_translation_domain' => true,
'trim' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'The selected choice is invalid.';
},
]);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);

View File

@ -121,6 +121,11 @@ class CollectionType extends AbstractType
'entry_type' => TextType::class,
'entry_options' => [],
'delete_empty' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'The collection is invalid.';
},
]);
$resolver->setNormalizer('entry_options', $entryOptionsNormalizer);

View File

@ -16,6 +16,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -69,6 +70,11 @@ class ColorType extends AbstractType
{
$resolver->setDefaults([
'html5' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please select a valid color.';
},
]);
$resolver->setAllowedTypes('html5', 'bool');

View File

@ -37,6 +37,11 @@ class CountryType extends AbstractType
'choice_translation_domain' => false,
'choice_translation_locale' => null,
'alpha3' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please select a valid country.';
},
]);
$resolver->setAllowedTypes('choice_translation_locale', ['null', 'string']);

View File

@ -35,6 +35,11 @@ class CurrencyType extends AbstractType
},
'choice_translation_domain' => false,
'choice_translation_locale' => null,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please select a valid currency.';
},
]);
$resolver->setAllowedTypes('choice_translation_locale', ['null', 'string']);

View File

@ -234,6 +234,11 @@ class DateIntervalType extends AbstractType
'compound' => $compound,
'empty_data' => $emptyData,
'labels' => [],
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please choose a valid date interval.';
},
]);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
$resolver->setNormalizer('labels', $labelsNormalizer);

View File

@ -273,6 +273,11 @@ class DateTimeType extends AbstractType
return $options['compound'] ? [] : '';
},
'input_format' => 'Y-m-d H:i:s',
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please enter a valid date and time.';
},
]);
// Don't add some defaults in order to preserve the defaults

View File

@ -299,6 +299,11 @@ class DateType extends AbstractType
},
'choice_translation_domain' => false,
'input_format' => 'Y-m-d',
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please enter a valid date.';
},
]);
$resolver->setNormalizer('placeholder', $placeholderNormalizer);

View File

@ -12,9 +12,25 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class EmailType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please enter a valid email address.';
},
));
}
/**
* {@inheritdoc}
*/

View File

@ -130,6 +130,11 @@ class FileType extends AbstractType
'empty_data' => $emptyData,
'multiple' => false,
'allow_file_upload' => true,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please select a valid file.';
},
]);
}

View File

@ -199,6 +199,8 @@ class FormType extends BaseType
'help_attr' => [],
'help_html' => false,
'help_translation_parameters' => [],
'invalid_message' => 'This value is not valid.',
'invalid_message_parameters' => [],
'is_empty_callback' => null,
]);

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class HiddenType extends AbstractType
@ -27,6 +28,11 @@ class HiddenType extends AbstractType
// Pass errors to the parent
'error_bubbling' => true,
'compound' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'The hidden field is invalid.';
},
]);
}

View File

@ -16,6 +16,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStri
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class IntegerType extends AbstractType
@ -48,6 +49,11 @@ class IntegerType extends AbstractType
// Integer cast rounds towards 0, so do the same when displaying fractions
'rounding_mode' => \NumberFormatter::ROUND_DOWN,
'compound' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please enter an integer.';
},
]);
$resolver->setAllowedValues('rounding_mode', [

View File

@ -54,6 +54,11 @@ class LanguageType extends AbstractType
'choice_translation_locale' => null,
'alpha3' => false,
'choice_self_translation' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please select a valid language.';
},
]);
$resolver->setAllowedTypes('choice_self_translation', ['bool']);

View File

@ -35,6 +35,11 @@ class LocaleType extends AbstractType
},
'choice_translation_domain' => false,
'choice_translation_locale' => null,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please select a valid locale.';
},
]);
$resolver->setAllowedTypes('choice_translation_locale', ['null', 'string']);

View File

@ -16,6 +16,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedString
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class MoneyType extends AbstractType
@ -57,6 +58,11 @@ class MoneyType extends AbstractType
'divisor' => 1,
'currency' => 'EUR',
'compound' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please enter a valid money amount.';
},
]);
$resolver->setAllowedValues('rounding_mode', [

View File

@ -63,6 +63,11 @@ class NumberType extends AbstractType
'compound' => false,
'input' => 'number',
'html5' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please enter a number.';
},
]);
$resolver->setAllowedValues('rounding_mode', [

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class PasswordType extends AbstractType
@ -36,6 +37,11 @@ class PasswordType extends AbstractType
$resolver->setDefaults([
'always_empty' => true,
'trim' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'The password is invalid.';
},
]);
}

View File

@ -57,6 +57,11 @@ class PercentType extends AbstractType
'symbol' => '%',
'type' => 'fractional',
'compound' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please enter a percentage value.';
},
]);
$resolver->setAllowedValues('type', [

View File

@ -12,9 +12,25 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class RadioType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please select a valid option.';
},
));
}
/**
* {@inheritdoc}
*/

View File

@ -12,9 +12,25 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class RangeType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please choose a valid range.';
},
));
}
/**
* {@inheritdoc}
*/

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\DataTransformer\ValueToDuplicatesTransformer;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class RepeatedType extends AbstractType
@ -57,6 +58,11 @@ class RepeatedType extends AbstractType
'first_name' => 'first',
'second_name' => 'second',
'error_bubbling' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'The values do not match.';
},
]);
$resolver->setAllowedTypes('options', 'array');

View File

@ -12,9 +12,25 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class SearchType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please enter a valid search term.';
},
));
}
/**
* {@inheritdoc}
*/

View File

@ -12,9 +12,25 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TelType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please provide a valid phone number.';
},
));
}
/**
* {@inheritdoc}
*/

View File

@ -336,6 +336,11 @@ class TimeType extends AbstractType
},
'compound' => $compound,
'choice_translation_domain' => false,
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please enter a valid time.';
},
]);
$resolver->setNormalizer('view_timezone', function (Options $options, $viewTimezone): ?string {

View File

@ -61,6 +61,12 @@ class TimezoneType extends AbstractType
'choice_translation_domain' => false,
'choice_translation_locale' => null,
'input' => 'string',
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please select a valid timezone.';
},
'regions' => \DateTimeZone::ALL,
]);
$resolver->setAllowedTypes('intl', ['bool']);

View File

@ -30,7 +30,7 @@ class TransformationFailureExtension extends AbstractTypeExtension
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!isset($options['invalid_message']) && !isset($options['invalid_message_parameters'])) {
if (!isset($options['constraints'])) {
$builder->addEventSubscriber(new TransformationFailureListener($this->translator));
}
}

View File

@ -16,6 +16,7 @@ use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UrlType extends AbstractType
@ -46,7 +47,14 @@ class UrlType extends AbstractType
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('default_protocol', 'http');
$resolver->setDefaults([
'default_protocol' => 'http',
'invalid_message' => function (Options $options, $previousValue) {
return ($options['legacy_error_messages'] ?? true)
? $previousValue
: 'Please enter a valid URL.';
},
]);
$resolver->setAllowedTypes('default_protocol', ['null', 'string']);
}

View File

@ -26,11 +26,13 @@ class FormTypeValidatorExtension extends BaseValidatorExtension
{
private $validator;
private $violationMapper;
private $legacyErrorMessages;
public function __construct(ValidatorInterface $validator)
public function __construct(ValidatorInterface $validator, bool $legacyErrorMessages = true)
{
$this->validator = $validator;
$this->violationMapper = new ViolationMapper();
$this->legacyErrorMessages = $legacyErrorMessages;
}
/**
@ -58,9 +60,18 @@ class FormTypeValidatorExtension extends BaseValidatorExtension
'constraints' => [],
'invalid_message' => 'This value is not valid.',
'invalid_message_parameters' => [],
'legacy_error_messages' => $this->legacyErrorMessages,
'allow_extra_fields' => false,
'extra_fields_message' => 'This form should not contain extra fields.',
]);
$resolver->setAllowedTypes('legacy_error_messages', 'bool');
$resolver->setDeprecated('legacy_error_messages', 'symfony/form', '5.2', function (Options $options, $value) {
if ($value === true) {
return 'Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.';
}
return '';
});
$resolver->setNormalizer('constraints', $constraintsNormalizer);
}

View File

@ -25,9 +25,12 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
class ValidatorExtension extends AbstractExtension
{
private $validator;
private $legacyErrorMessages;
public function __construct(ValidatorInterface $validator)
public function __construct(ValidatorInterface $validator, bool $legacyErrorMessages = true)
{
$this->legacyErrorMessages = $legacyErrorMessages;
$metadata = $validator->getMetadataFor('Symfony\Component\Form\Form');
// Register the form constraints in the validator programmatically.
@ -50,7 +53,7 @@ class ValidatorExtension extends AbstractExtension
protected function loadTypeExtensions()
{
return [
new Type\FormTypeValidatorExtension($this->validator),
new Type\FormTypeValidatorExtension($this->validator, $this->legacyErrorMessages),
new Type\RepeatedTypeValidatorExtension(),
new Type\SubmitTypeValidatorExtension(),
];

View File

@ -18,6 +18,102 @@
<source>This value is not a valid HTML5 color.</source>
<target>This value is not a valid HTML5 color.</target>
</trans-unit>
<trans-unit id="100">
<source>Please enter a valid birthdate.</source>
<target>Please enter a valid birthdate.</target>
</trans-unit>
<trans-unit id="101">
<source>The selected choice is invalid.</source>
<target>The selected choice is invalid.</target>
</trans-unit>
<trans-unit id="102">
<source>The collection is invalid.</source>
<target>The collection is invalid.</target>
</trans-unit>
<trans-unit id="103">
<source>Please select a valid color.</source>
<target>Please select a valid color.</target>
</trans-unit>
<trans-unit id="104">
<source>Please select a valid country.</source>
<target>Please select a valid country.</target>
</trans-unit>
<trans-unit id="105">
<source>Please select a valid currency.</source>
<target>Please select a valid currency.</target>
</trans-unit>
<trans-unit id="106">
<source>Please choose a valid date interval.</source>
<target>Please choose a valid date interval.</target>
</trans-unit>
<trans-unit id="107">
<source>Please enter a valid date and time.</source>
<target>Please enter a valid date and time.</target>
</trans-unit>
<trans-unit id="108">
<source>Please enter a valid date.</source>
<target>Please enter a valid date.</target>
</trans-unit>
<trans-unit id="109">
<source>Please select a valid file.</source>
<target>Please select a valid file.</target>
</trans-unit>
<trans-unit id="110">
<source>The hidden field is invalid.</source>
<target>The hidden field is invalid.</target>
</trans-unit>
<trans-unit id="111">
<source>Please enter an integer.</source>
<target>Please enter an integer.</target>
</trans-unit>
<trans-unit id="112">
<source>Please select a valid language.</source>
<target>Please select a valid language.</target>
</trans-unit>
<trans-unit id="113">
<source>Please select a valid locale.</source>
<target>Please select a valid locale.</target>
</trans-unit>
<trans-unit id="114">
<source>Please enter a valid money amount.</source>
<target>Please enter a valid money amount.</target>
</trans-unit>
<trans-unit id="115">
<source>Please enter a number.</source>
<target>Please enter a number.</target>
</trans-unit>
<trans-unit id="116">
<source>The password is invalid.</source>
<target>The password is invalid.</target>
</trans-unit>
<trans-unit id="117">
<source>Please enter a percentage value.</source>
<target>Please enter a percentage value.</target>
</trans-unit>
<trans-unit id="118">
<source>The values do not match.</source>
<target>The values do not match.</target>
</trans-unit>
<trans-unit id="119">
<source>Please enter a valid time.</source>
<target>Please enter a valid time.</target>
</trans-unit>
<trans-unit id="120">
<source>Please select a valid timezone.</source>
<target>Please select a valid timezone.</target>
</trans-unit>
<trans-unit id="121">
<source>Please enter a valid URL.</source>
<target>Please enter a valid URL.</target>
</trans-unit>
<trans-unit id="122">
<source>Please enter a valid search term.</source>
<target>Please enter a valid search term.</target>
</trans-unit>
<trans-unit id="123">
<source>Please provide a valid phone number.</source>
<target>Please provide a valid phone number.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -39,6 +39,6 @@ trait ValidatorExtensionTrait
$this->validator->expects($this->any())->method('getMetadataFor')->will($this->returnValue($metadata));
$this->validator->expects($this->any())->method('validate')->will($this->returnValue(new ConstraintViolationList()));
return new ValidatorExtension($this->validator);
return new ValidatorExtension($this->validator, false);
}
}

View File

@ -23,7 +23,7 @@ class FormValidatorPerformanceTest extends FormPerformanceTestCase
protected function getExtensions()
{
return [
new ValidatorExtension(Validation::createValidator()),
new ValidatorExtension(Validation::createValidator(), false),
];
}

View File

@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class BirthdayTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(BirthdayType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please enter a valid birthdate.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class CheckboxTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(CheckboxType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('The checkbox has an invalid value.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,49 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class ChoiceTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(ChoiceType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('The selected choice is invalid.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class CollectionTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(CollectionType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('The collection is invalid.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\ColorType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class ColorTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(ColorType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please select a valid color.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CountryType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class CountryTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(CountryType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please select a valid country.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class CurrencyTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(CurrencyType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please select a valid currency.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateIntervalType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class DateIntervalTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(DateIntervalType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please choose a valid date interval.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class DateTimeTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(DateTimeType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please enter a valid date and time.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class DateTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(DateType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please enter a valid date.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class EmailTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(EmailType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please enter a valid email address.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class FileTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(FileType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please select a valid file.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\Forms;
@ -29,6 +30,7 @@ use Symfony\Component\Validator\Validation;
class FormTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
public function testSubmitValidatesData()
@ -62,7 +64,7 @@ class FormTypeValidatorExtensionTest extends BaseValidatorExtensionTest
public function testGroupSequenceWithConstraintsOption()
{
$form = Forms::createFormFactoryBuilder()
->addExtension(new ValidatorExtension(Validation::createValidator()))
->addExtension(new ValidatorExtension(Validation::createValidator(), false))
->getFormFactory()
->create(FormTypeTest::TESTED_TYPE, null, (['validation_groups' => new GroupSequence(['First', 'Second'])]))
->add('field', TextTypeTest::TESTED_TYPE, [
@ -133,6 +135,25 @@ class FormTypeValidatorExtensionTest extends BaseValidatorExtensionTest
$this->assertSame('children[lastName].data', $errors[0]->getCause()->getPropertyPath());
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertEquals('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array('legacy_error_messages' => true));
$this->assertEquals('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
protected function createForm(array $options = [])
{
return $this->factory->create(FormTypeTest::TESTED_TYPE, null, $options);

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class HiddenTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(HiddenType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('The hidden field is invalid.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class IntegerTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(IntegerType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please enter an integer.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class LanguageTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(LanguageType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please select a valid language.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class LocaleTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(LocaleType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please select a valid locale.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class MoneyTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(MoneyType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please enter a valid money amount.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class NumberTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(NumberType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please enter a number.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class PasswordTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(PasswordType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('The password is invalid.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\PercentType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class PercentTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(PercentType::class, null, $options + ['rounding_mode' => \NumberFormatter::ROUND_CEILING]);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please enter a percentage value.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\RadioType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class RadioTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(RadioType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please select a valid option.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\RangeType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class RangeTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(RangeType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please choose a valid range.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class RepeatedTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(RepeatedType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('The values do not match.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\SearchType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class SearchTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(SearchType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please enter a valid search term.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class TelTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(TelType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please provide a valid phone number.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TimeType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class TimeTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(TimeType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please enter a valid time.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class TimezoneTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(TimezoneType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please select a valid timezone.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
class UrlTypeValidatorExtensionTest extends BaseValidatorExtensionTest
{
use ExpectDeprecationTrait;
use ValidatorExtensionTrait;
protected function createForm(array $options = array())
{
return $this->factory->create(UrlType::class, null, $options);
}
public function testInvalidMessage()
{
$form = $this->createForm();
$this->assertSame('Please enter a valid URL.', $form->getConfig()->getOption('invalid_message'));
}
/**
* @group legacy
*/
public function testLegacyInvalidMessage()
{
$this->expectDeprecation('Since symfony/form 5.2: Setting the "legacy_error_messages" option to "true" is deprecated. It will be disabled in Symfony 6.0.');
$form = $this->createForm(array(
'legacy_error_messages' => true,
));
$this->assertSame('This value is not valid.', $form->getConfig()->getOption('invalid_message'));
}
}

View File

@ -35,7 +35,7 @@ class ValidatorExtensionTest extends TestCase
->setMetadataFactory($metadataFactory)
->getValidator();
$extension = new ValidatorExtension($validator);
$extension = new ValidatorExtension($validator, false);
$this->assertInstanceOf(ValidatorTypeGuesser::class, $extension->loadTypeGuesser());

View File

@ -23,6 +23,7 @@
"data_class",
"empty_data",
"error_bubbling",
"invalid_message",
"trim"
]
},
@ -43,6 +44,7 @@
"help_html",
"help_translation_parameters",
"inherit_data",
"invalid_message_parameters",
"is_empty_callback",
"label",
"label_attr",

View File

@ -11,8 +11,8 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (Block prefix: "choice")
choice_loader data_class allow_file_upload csrf_message
choice_name empty_data attr csrf_protection
choice_translation_domain error_bubbling attr_translation_parameters csrf_token_id
choice_value trim auto_initialize csrf_token_manager
choices block_name
choice_value invalid_message auto_initialize csrf_token_manager
choices trim block_name
expanded block_prefix
group_by by_reference
multiple data
@ -22,6 +22,7 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (Block prefix: "choice")
help_html
help_translation_parameters
inherit_data
invalid_message_parameters
is_empty_callback
label
label_attr

View File

@ -22,6 +22,8 @@
"help_html",
"help_translation_parameters",
"inherit_data",
"invalid_message",
"invalid_message_parameters",
"is_empty_callback",
"label",
"label_attr",

View File

@ -24,6 +24,8 @@ Symfony\Component\Form\Extension\Core\Type\FormType (Block prefix: "form")
help_html
help_translation_parameters
inherit_data
invalid_message
invalid_message_parameters
is_empty_callback
label
label_attr