8000 [Form] Allowed native framework errors to be mapped as well · symfony/symfony@ac69394 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac69394

Browse files
committed
[Form] Allowed native framework errors to be mapped as well
1 parent 59d6b55 commit ac69394

25 files changed

+1481
-745
lines changed

UPGRADE-2.1.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,26 @@
539539
$form->getConfig()->getErrorBubbling();
540540
```
541541
542+
* The option "validation_constraint" is deprecated and will be removed
543+
in Symfony 2.3. You should use the option "constraints" instead,
544+
where you can pass one or more constraints for a form.
545+
546+
Before:
547+
548+
```
549+
$builder->add('name', 'text', array(
550+
'validation_constraint' => new NotBlank(),
551+
));
552+
```
553+
554+
After (if the address object is an array):
555+
556+
```
557+
$builder->add('name', 'text', array(
558+
'constraints' => new NotBlank(),
559+
));
560+
```
561+
542562
### Validator
543563
544564
* The methods `setMessage()`, `getMessageTemplate()` and

src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@
133133
</service>
134134

135135
<!-- FormTypeValidatorExtension -->
136-
<service id="form.type_extension.field" class="Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension">
136+
<service id="form.type_extension.form.validator" class="Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension">
137137
<tag name="form.type_extension" alias="form" />
138138
<argument type="service" id="validator" />
139139
</service>
140+
<service id="form.type_extension.repeated.validator" class="Symfony\Component\Form\Extension\Validator\Type\RepeatedTypeValidatorExtension">
141+
<tag name="form.type_extension" alias="repeated" />
142+
</service>
140143
</services>
141144
</container>

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,5 @@ CHANGELOG
8383
* `getErrorBubbling`
8484
* `getNormTransformers`
8585
* `getClientTransformers`
86+
* deprecated the option "validation_constraint" in favor of the new
87+
option "constraints"

src/Symfony/Component/Form/Extension/Core/EventListener/ValidationListener.php

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ public function buildForm(FormBuilder $builder, array $options)
5151
'days',
5252
'empty_value',
5353
'required',
54-
'invalid_message',
55-
'invalid_message_parameters',
5654
'translation_domain',
5755
)));
5856
$timeOptions = array_intersect_key($options, array_flip(array(
@@ -62,8 +60,6 @@ public function buildForm(FormBuilder $builder, array $options)
6260
'with_seconds',
6361
'empty_value',
6462
'required',
65-
'invalid_message',
66-
'invalid_message_parameters',
6763
'translation_domain',
6864
)));
6965

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\Form\FormFactoryInterface;
1919
use Symfony\Component\Form\FormView;
2020
use Symfony\Component\Form\Extension\Core\EventListener\TrimListener;
21-
use Symfony\Component\Form\Extension\Core\EventListener\ValidationListener;
2221
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
2322
use Symfony\Component\EventDispatcher\EventDispatcher;
2423
use Symfony\Component\Form\Exception\FormException;
@@ -50,19 +49,15 @@ public function buildForm(FormBuilder $builder, array $options)
5049
->setVirtual($options['virtual'])
5150
->setAttribute('read_only', $options['read_only'])
5251
->setAttribute('by_reference', $options['by_reference'])
53-
->setAttribute('error_mapping', $options['error_mapping'])
5452
->setAttribute('max_length', $options['max_length'])
5553
->setAttribute('pattern', $options['pattern'])
5654
->setAttribute('label', $options['label'] ?: $this->humanize($builder->getName()))
5755
->setAttribute('attr', $options['attr'])
5856
->setAttribute('label_attr', $options['label_attr'])
59-
->setAttribute('invalid_message', $options['invalid_message'])
60-
->setAttribute('invalid_message_parameters', $options['invalid_message_parameters'])
6157
->setAttribute('translation_domain', $options['translation_domain'])
6258
->setAttribute('single_control', $options['single_control'])
6359
->setData($options['data'])
6460
->setDataMapper(new PropertyPathMapper())
65-
->addEventSubscriber(new ValidationListener())
6661
;
6762

6863
if ($options['trim']) {
@@ -197,27 +192,24 @@ public function getDefaultOptions()
197192
};
198193

199194
return array(
200-
'data' => null,
201-
'data_class' => $dataClass,
202-
'empty_data' => $emptyData,
203-
'trim' => true,
204-
'required' => true,
205-
'read_only' => false,
206-
'disabled' => false,
207-
'max_length' => null,
208-
'pattern' => null,
209-
'property_path' => null,
210-
'mapped' => $mapped,
211-
'by_reference' => true,
212-
'error_bubbling' => $errorBubbling,
213-
'error_mapping' => array(),
214-
'label' => null,
215-
'attr' => array(),
216-
'label_attr' => array(),
217-
'virtual' => false,
218-
'single_control' => false,
219-
'invalid_message' => 'This value is not valid.',
220-
'invalid_message_parameters' => array(),
195+
'data' => null,
196+
'data_class' => $dataClass,
197+
'empty_data' => $emptyData,
198+
'trim' => true,
199+
'required' => true,
200+
'read_only' => false,
201+
'disabled' => false,
202+
'max_length' => null,
203+
'pattern' => null,
204+
'property_path' => null,
205+
'mapped' => $mapped,
206+
'by_reference' => true,
207+
'error_bubbling' => $errorBubbling,
208+
'label' => null,
209+
'attr' => array(),
210+
'label_attr' => array(),
211+
'virtual' => false,
212+
'single_control' => false,
221213
'translation_domain' => 'messages',
222214
);
223215
}

src/Symfony/Component/Form/Extension/Core/Type/RepeatedType.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public function buildForm(FormBuilder $builder, array $options)
4242
*/
4343
public function getDefaultOptions()
4444
{
45-
// Map errors to the first field
46-
$errorMapping = function (Options $options) {
47-
return array('.' => $options['first_name']);
48-
};
49-
5045
return array(
5146
'type' => 'text',
5247
'options' => array(),
@@ -55,7 +50,6 @@ public function getDefaultOptions()
5550
'first_name' => 'first',
5651
'second_name' => 'second',
5752
'error_bubbling' => false,
58-
'error_mapping' => $errorMapping,
5953
);
6054
}
6155

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Extension\Validator\Constraints;
13+
14+
use Symfony\Component\Validator\Constraint;
15+
16+
/**
17+
* @author Bernhard Schussek <bschussek@gmail.com>
18+
*/
19+
class Form extends Constraint
20+
{
21+
/**
22+
* Violation code marking an invalid form.
23+
*/
24+
const ERR_INVALID = 1;
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function getTargets()
30+
{
31+
return self::CLASS_CONSTRAINT;
32+
}
33+
}

0 commit comments

Comments
 (0)
0