Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8295129

Browse filesBrowse files
huebsweaverryan
authored andcommitted
Improve Choice Validation Constraint Example
Example came off sounding transphobic. Added "other" option.
1 parent 283c157 commit 8295129
Copy full SHA for 8295129

File tree

Expand file treeCollapse file tree

1 file changed

+9
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-7
lines changed

‎book/validation.rst

Copy file name to clipboardExpand all lines: book/validation.rst
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ Some constraints, like :doc:`NotBlank </reference/constraints/NotBlank>`,
329329
are simple whereas others, like the :doc:`Choice </reference/constraints/Choice>`
330330
constraint, have several configuration options available. Suppose that the
331331
``Author`` class has another property called ``gender`` that can be set to either
332-
"male" or "female":
332+
"male", "female", or "other":
333333

334334
.. configuration-block::
335335

@@ -344,7 +344,7 @@ constraint, have several configuration options available. Suppose that the
344344
{
345345
/**
346346
* @Assert\Choice(
347-
* choices = { "male", "female" },
347+
* choices = { "male", "female", "other" },
348348
* message = "Choose a valid gender."
349349
* )
350350
*/
@@ -359,7 +359,7 @@ constraint, have several configuration options available. Suppose that the
359359
AppBundle\Entity\Author:
360360
properties:
361361
gender:
362-
- Choice: { choices: [male, female], message: Choose a valid gender. }
362+
- Choice: { choices: [male, female, other], message: Choose a valid gender. }
363363
# ...
364364
365365
.. code-block:: xml
@@ -376,6 +376,7 @@ constraint, have several configuration options available. Suppose that the
376376
<option name="choices">
377377
<value>male</value>
378378
<value>female</value>
379+
<value>other</value>
379380
</option>
380381
<option name="message">Choose a valid gender.</option>
381382
</constraint>
@@ -404,7 +405,7 @@ constraint, have several configuration options available. Suppose that the
404405
// ...
405406
406407
$metadata->addPropertyConstraint('gender', new Assert\Choice(array(
407-
'choices' => array('male', 'female'),
408+
'choices' => array('male', 'female', 'other'),
408409
'message' => 'Choose a valid gender.',
409410
)));
410411
}
@@ -429,7 +430,7 @@ options can be specified in this way.
429430
class Author
430431
{
431432
/**
432-
* @Assert\Choice({"male", "female"})
433+
* @Assert\Choice({"male", "female", "other"})
433434
*/
434435
protected $gender;
435436
@@ -442,7 +443,7 @@ options can be specified in this way.
442443
AppBundle\Entity\Author:
443444
properties:
444445
gender:
445-
- Choice: [male, female]
446+
- Choice: [male, female,other]
446447
# ...
447448
448449
.. code-block:: xml
@@ -458,6 +459,7 @@ options can be specified in this way.
458459
<constraint name="Choice">
459460
<value>male</value>
460461
<value>female</value>
462+
<value>other</value>
461463
</constraint>
462464
</property>
463465
@@ -483,7 +485,7 @@ options can be specified in this way.
483485
484486
$metadata->addPropertyConstraint(
485487
'gender',
486-
new Assert\Choice(array('male', 'female'))
488+
new Assert\Choice(array('male', 'female', 'other'))
487489
);
488490
}
489491
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.