@@ -164,9 +164,7 @@ that if either of the ``personal_email`` or ``short_bio`` elements were missing
164
164
from the ``$personalData `` property, no validation error would occur.
165
165
166
166
.. versionadded :: 2.1
167
- The ``Required `` and ``Optional `` constraint classes were added to give additional
168
- flexibility over the existing ``allowExtraFields `` and ``allowMissingFields `` options
169
- for fields within a Collection.
167
+ The ``Required `` and ``Optional `` constraints are new to Symfony 2.1.
170
168
171
169
Required and Optional Field Constraints
172
170
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -195,13 +193,13 @@ field is optional but must be a valid email if supplied, you can do the followin
195
193
/**
196
194
* @Assert\Collection(
197
195
* fields={
198
- * "personal_email" = @Required({@Assert\NotBlank, @Assert\Email}),
196
+ * "personal_email" = @Required({@Assert\NotBlank, @Assert\Email}),
199
197
* "alternate_email" = @Optional({@Assert\Email}),
200
198
* }
201
199
* )
202
200
*/
203
201
protected $profileData = array(
204
- 'personal_email'
202
+ 'personal_email',
205
203
);
206
204
}
207
205
@@ -217,15 +215,15 @@ field is optional but must be a valid email if supplied, you can do the followin
217
215
218
216
class Author
219
217
{
220
- private $options = array();
218
+ protected $profileData = array('personal_email' );
221
219
222
220
public static function loadValidatorMetadata(ClassMetadata $metadata)
223
221
{
224
222
$metadata->addPropertyConstraint('profileData', new Assert\Collection(array(
225
223
'fields' => array(
226
- 'personal_email' => new Required(array(new Assert\NotBlank(), new Assert\Email())),
224
+ 'personal_email' => new Required(array(new Assert\NotBlank(), new Assert\Email())),
227
225
'alternate_email' => new Optional(array(new Assert\Email())),
228
- )
226
+ ),
229
227
)));
230
228
}
231
229
}
0 commit comments